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

[987 byte] By [advaitsamanta] at [2007-11-27 5:24:59]
# 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

bsampieria at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 2
You never need to call updateui().
mpmarronea at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 3
4. You cannot call swing component methods (such as updateUI()) from outside the event thread, it will often result in an exception.
mpmarronea at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 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

advaitsamanta at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 5
your tree model should fire tree change events.
bsampieria at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 6
your tree model?I dont have any tree model implementaion? So Jtree will use default one.Are you sugessting to call API of tree model?
advaitsamanta at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 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.

bsampieria at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...
# 8
Cool.Thanks for the help.And here goes the remaining duke star.
advaitsamanta at 2007-7-12 14:44:46 > top of Java-index,Desktop,Core GUI APIs...