| Author |
JTree help
|
Anand Loni
Ranch Hand
Joined: Jan 20, 2006
Posts: 150
|
|
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
|
~ Anand,
SCJP 1.5
SCWCD 1.5
|
 |
Craig Wood
Ranch Hand
Joined: Jan 14, 2004
Posts: 1535
|
|
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
Joined: Jan 20, 2006
Posts: 150
|
|
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
Joined: Jan 14, 2004
Posts: 1535
|
|
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.
|
 |
 |
|
|
subject: JTree help
|
|
|