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/

 

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

 

Reply via email to