Hi,
Whilst I could perhaps provide some very minor tweaks to the wording you
are adding, I would first like to understand the details of why the
rendering
becomes broken here since there doesn't seem to be anything intrinsically
wrong - only the model is being updated.
I've found that commenting out one of the other listener methods
BasicTreeUI.Handler.treeNodesInserted - "cures" it.
So what we seem to be saying here, is that when you get notification
of a change in the model, you must not make further changes in the model
until any UI listener has processed the first change .. and throwing this
on the queue via invokeLater is the obvious way to do that.
But I've run out of time to look at quite where the rendering breaks
and I'm not sure if this is as general a problem as the new comment
would imply.
So can you say something about why we miss rendering some nodes
and quite why BasicTreeUI.Handler.treeNodesInserted is breaking it.
-phil.
On 11/12/2017 11:07 PM, Krishna Addepalli wrote:
Hi Sergey,
Gentle reminder. Could you review?
Thanks,
Krishna
*From:* Krishna Addepalli
*Sent:* Wednesday, November 8, 2017 8:22 PM
*To:* [email protected]
*Subject:* RE: [10][JDK-8187936] Automatically selecting a new JTree
node in a model listener can cause unusual behavior.
Hi Sergey,
Could you review this and let me know your feedback?
Thanks,
Krishna
*From:* Krishna Addepalli
*Sent:* Friday, October 27, 2017 4:43 PM
*To:* [email protected] <mailto:[email protected]>
*Subject:* [10][JDK-8187936] Automatically selecting a new JTree node
in a model listener can cause unusual behavior.
Hi All,
Please review the help text that is updated for this bug:
Bug: JDK-8187936: https://bugs.openjdk.java.net/browse/JDK-8187936
Webrev: http://cr.openjdk.java.net/~kaddepalli/8187936/webrev00/
<http://cr.openjdk.java.net/%7Ekaddepalli/8187936/webrev00/>
Summary:
As the bug title mentions, this is an unrecommended way of using the
model listeners. The code posted in the bug tries to update the JTree
path in the model listener callback, and since the JTree is yet to
change itself to the underlying model, it results in weird UI behavior.
Attached code in the bug is corrected and re-uploaded.
This typically happens since listeners are called in a particular
order (either last to first or first to last in the order of
registration), and if the model listener tries to change the GUI
before the GUI has had a chance to react itself to the changes in the
underlying model. For example, highlighting a selection path for a
node added in the JTree, in the TreeModelListener callback could lead
to an extra node being added or existing nodes not being shown, since
JTree would not have yet updated its state based on the model changes.
In such cases it is recommended to wrap the callback function contents
into a lambda, and invoke it through “SwingUtilities.invokeLater”.
This ensures that all the UI elements have had a chance to react to
the model changes, and any UI actions will be guaranteed to operate on
the updated widgets.
Similar update has been done in package-info.java for Swing, so that
it acts as a reference.
Thanks,
Krishna