Null pointer after calling updateUI in JTree
This is a known issue it seems but i am trying to explore the root cause!!
When i remove few nodes from the tree i am calling updateUI() method.
This results into null pointer expection.
Similar problem is discussed in following link.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4524304
Here are the doubts i have-
1. Do i really need to call updateUI method after removing nodes from tree?
When i remove this call i found that tree is updated. But i am afraid if later this might result into regression!!
2. If i add node and then call updateUI method tree is updated without any expection.
3. Even after encountering expection the tree is updated. Then what kind of expection is this?
4. When having such code in a multithreaded application, sometimes after this exception UI completely grays out. What could be the reason?
Any help in this regards will be highly appreciated.
Thanks,
~Advait
# 1
A) What exactly is the exception?
B) You should never have to call updateUI unless you are updating the UI. (By this I mean updating the Look & Feel stuff)
Removing nodes from a tree is not a UI update (insofar as the updateUI() method is concerned), it's a tree structure change that should be controlled via the tree model and using the tree structure events.
Regarding #3, probably because the exception is not interrupting the painting manager or event dispatch thread or whatever.
Regarding #4, I've never heard of this, but remember that all UI changes (including updateUI() calls) should be done on the event dispatch thread (see SwingUtilities.invokeXxx(Runnable)).
Message was edited by:
bsampieri
# 4
Thanks a lot for your replies.
So what i undestand now is on altering tree i.e. after adding and removing nodes from existing tree, i dont need to call updateUI.
[My query] So will my tree be updated without calling updateUI? Do i need to call any other API so that tree is refreshed after altering it?
~Advait
# 7
You always have a tree model. You should add/remove nodes by changing the model, which will in turn notify the tree of the change.
Or if you are using DefaultMutableTreeNodes, you can add/remove nodes from the parent node, then call DefaultTreeModel's reload(TreeNode) method to refresh the tree.