NullPointerException in BasicTreeUI.isToggleEvent

Nick Gusev

Usenet Archive
Joined
Jun 17, 2004
Messages
1
Reaction score
0
Just in case if somebody need it. I didn't find this anywhere. If you are getting after invoking JTree.updateUI something like:

java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.completeEditing(BasicTreeUI.java:1880) at javax.swing.plaf.basic.BasicTreeUI$TreeSelectionHandler.valueChanged(BasicTreeUI.java:2496) at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629) at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1076) at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287) at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170) at javax.swing.JTree.setSelectionPath(JTree.java:1168) at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2192) … all you need to know that it's bad idea to update UI in order to refresh a tree. All pending events will be for old UI with tree == null. JTree.updateUI replaces UI with new one from UIManager and calls JTree.invalidate. So just call JTree.invalidate instead. This should solve the problem.
 

Thomas Weidenfeller

Usenet Archive
Joined
May 25, 2000
Messages
1,555
Reaction score
0
Nick said:
all you need to know that it's bad idea to update UI in order to refresh a tree.

Often a need for refreshing a tree arises if the model is not firing the necessary change events. Instead of torturing the innocent JTree widget you might want to check your model implementation and behavior and fix it if needed.

/Thomas
 
Joined
Nov 18, 2014
Messages
1
Reaction score
0
Just in case if somebody need it. I didn't find this anywhere. If you
are getting after invoking JTree.updateUI something like:

java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTreeUI.completeEditing(BasicTreeUI.java:1880)
at javax.swing.plaf.basic.BasicTreeUI$TreeSelectionHandler.valueChanged(BasicTreeUI.java:2496)
at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:629)
at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1076)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:287)
at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:170)
at javax.swing.JTree.setSelectionPath(JTree.java:1168)
at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2192)
…
all you need to know that it's bad idea to update UI in order to
refresh a tree. All pending events will be for old UI with tree ==
null. JTree.updateUI replaces UI with new one from UIManager and calls
JTree.invalidate. So just call JTree.invalidate instead. This should
solve the problem.


thanks.. the suggestion is quite helpful. The exceptions are gone however it is not refreshing tree as in UpdateUI
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,049
Messages
3,104,245
Members
248,133
Latest member
DujonT

Latest Threads

Top