Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree help

 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using Jtree with DefaultTreeModel and whose nodes are DefaultMutableTreeNode. I have associated JpopupMenu with tree. When I click rename from popup I want to make the selected tree node editable.
Is there any method to do this ? AnyBody can Help....

Regards,
Anand
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the tree is using a DefaultTreeModel and is editable the default editor is DefaultTreeCellEditor. See the discussion section of this class for the two gestures that trigger editing. Use of the popupMenu button makes three. Press the "enter" key after the edit to save the new value to the model.

edit words at top for clarity
[ February 24, 2006: Message edited by: Craig Wood ]
 
Anand Loni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx,

This code is Ok , I found the method startEditingAt() but when I start editing popup is not displayed(in my case it should show same popup when we do not edit node). Also I have set CellRenderer for tree to do not show icon and for some other purpose ,then also it is showing icon for editing node.

why this is happening ???
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when I start editing popup is not displayed
You can locate it wherever you want and call setVisible to keep it there. Or you can move it around:

CellRenderer for tree to ... not show icon
You can make up an editor to match your CellRenderer. If you use DefaultTreeCellEditor it has a constructor in which you can specify your renderer as an argument, see api.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic