NullPointerException in BasicTreeUI.isToggleEvent

N

Nick Gusev

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.
 
T

Thomas Weidenfeller

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
473,813
Messages
2,569,696
Members
45,483
Latest member
TedDvb6626

Latest Threads

Top