JTree problem (0/1)

V

Vincent H

Hi,

For a project I'm working on I'm building a GUI that uses a JTree. This tree represents groups of hardware. Each node
represents such a piece of hardware. The name that is presented by the node is either the ip-address or the name of the
system and possilby a different color when the system is on-line. To be able to do that I'm using my own
TreeCellRenderer. The grouping of systems is handled by a TreeModel I made.

Now when I detect that a system becomes on-line, I update the model and trigger the TreeModelListeners'
treeNodeChanged() methods. I can see the tree change but when the string presented is longer that the initial string it
is truncated (ellipses are shown). I can't figure out what I'm doing wrong here.

To actually show what I'm experiencing I've made a small demo app that presents the problem. The classes are attached.
On the GUI press the "Hit Me!" button to make a different team become the champion (yeah I had to find some kind of
example). To see the problem you have to expand all nodes before hitting the button.

Has anyone experienced this? Any suggestions how to resolve this elegantly?

Thanks!

Vincent Hartsteen
 
J

Jim Sculley

Vincent said:
Hi,

For a project I'm working on I'm building a GUI that uses a JTree. This tree represents groups of hardware. Each node
represents such a piece of hardware. The name that is presented by the node is either the ip-address or the name of the
system and possilby a different color when the system is on-line. To be able to do that I'm using my own
TreeCellRenderer. The grouping of systems is handled by a TreeModel I made.

Now when I detect that a system becomes on-line, I update the model and trigger the TreeModelListeners'
treeNodeChanged() methods. I can see the tree change but when the string presented is longer that the initial string it
is truncated (ellipses are shown). I can't figure out what I'm doing wrong here.

To actually show what I'm experiencing I've made a small demo app that presents the problem. The classes are attached.
On the GUI press the "Hit Me!" button to make a different team become the champion (yeah I had to find some kind of
example). To see the problem you have to expand all nodes before hitting the button.

Has anyone experienced this? Any suggestions how to resolve this elegantly?

See

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=147624

Jim S.
 
J

jonck

Actually I've experienced this just recently. I found out that to solve
this, instead of creating a two-argument TreeModelEvent(Object sourc,
TreePath path), you need to create a 4-argument TreeModelEvent(Object
source, TreePath path, int[] childIndices, Object[] children).
Note that the second argument here differs depending on which
fireTreeNodeXXX method you're going to call. When calling the
fireTreeNodesInserted or fireTreeNodesRemoved method, the path argument
should be a path leading to the parent. When you want to call the
fireTreeNodesChanged method the path argument should be a path leading
to the child.

Regards, Jonck
 
V

Vincent H

Actually I've experienced this just recently. I found out that to solve
this, instead of creating a two-argument TreeModelEvent(Object sourc,
TreePath path), you need to create a 4-argument TreeModelEvent(Object
source, TreePath path, int[] childIndices, Object[] children).
Note that the second argument here differs depending on which
fireTreeNodeXXX method you're going to call. When calling the
fireTreeNodesInserted or fireTreeNodesRemoved method, the path argument
should be a path leading to the parent. When you want to call the
fireTreeNodesChanged method the path argument should be a path leading
to the child.

Regards, Jonck


Thanks! This actually works for me. The other solution suggested in this thread makes sense to me as well. However it
did not seem to work. Using the 4 arg constructor of the TreeModelEvent works like a charm though. In hindsight the
javadoc makes sense as well.

Thanks for your input.

Vincent
 

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

Similar Threads

JTree problem 0
[SWING] Problem with JTree 2
Extra Row in JTree 6
Jtree renderers 0
Modify JTree look and feel 7
JTree? 10
Jtree contenthandlers 0
HyperlinkListener in JTree 3

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top