• Post Reply Bookmark Topic Watch Topic
  • New Topic

components integrated to a DefaultMutableTreeNode are not accessible.  RSS feed

 
samantha clarkson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Thank you for helping
the screenshot is attached to the message.

First Problem : I have 4 components included to a DefaultMutableTreeNode (JLabel, JtextFiled, 2 Jbuttons), i can't access to the textFiled or the Buttons for editting.

Second Problem : i have un undeterminate ProgressBar included to a DefaultMutableTreeNode which stay static, it progress just in case of selecting the node where it is included.Normally it should evoluate constantly.

I implemented renderers to have the graphic presentation of the tree.
Thank you.

[screen shot removed at author's request]
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) How have you added these controls? Using a TreeCellRenderer?
TreeCellRenderers (TableCellRenderers/ListCellRenderers) do not really put a real component into the JTree (JTable/JList) - it just uses the return value of getTreeRendererComponent (getTableRendererComponent/getListRendererComponent) to draw something into the JTree (JTable/JList).

You want to edit a node, so you should use a custom TreeCellEditor as well, and make the JTree editable.


2) Well, I explained the reason above. The solution is a bit harder; you'll need to repaint that node very very often. Firing a treeNodeChanged event would do that, but you would need a javax.swing.Timer for firing the events.
 
samantha clarkson
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thank you very much Rob Prime.
Yes effectively I implemented the interface TreeCellRenderer to have these representation. Ok i will see how to do with the TreeCellEditor.
But i have a question for the second problem, the node containing the progressBar contains children nodes so if i repaint it many times it will collapse each time so i will never see its children nodes.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That shouldn't happen (from a logical point of view). The treeNodesChanged event is only for when the value has changed. The structure of the node is still the same.

If it will collapse your tree, you need to store the expanded state of the tree before, then restore it.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!