aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTree Node Edit only from Popup menu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree Node Edit only from Popup menu" Watch "JTree Node Edit only from Popup menu" New topic
Author

JTree Node Edit only from Popup menu

Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
I have a jtree with nodes that when right clicked pops up a menu to rename the nodes. This works fine, my problem is since i have to set the setEditable(true), the tree also allows users to edit it by clicking 3 times or by pressing F2 key. I need to be able to disable these and allow edit only via the popup menu.. any suggestions???
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
Why not make all nodes non-editable. Then when you choose the right menu option on a node, temporarily make it editable (you must know which node you clicked on or you wouldn't be able to rename it), and then after the rename set it to non-editable again.
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Thanks for the input stuart, i did try it but it doesn't seem to be working, i am posting the code here, take a look and let me know where i am going wrong.


and when I create the tree i've set the editable field to false.
what am i doing wrong here??
[ April 29, 2005: Message edited by: Sudhakar Krishnamurthy ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

it doesn't seem to be working

How so? The only thing I noticed is that you set the tree to be editable and then after you perform your action, you never set the tree to be uneditable again.


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Out of curiosity, if you are allowing the user to change the name of the nodes with a context menu, why not let them us F2, etc? Why go to all this trouble?
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Thanks Gregg,
If you see the last line in the code, i am setting the tree to be non-editable...or should i move that up into the action performed method???

About F2, its one of the lame requirements that we have

TIA
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Sudhakar Krishnamurthy:
Thanks Gregg,
If you see the last line in the code, i am setting the tree to be non-editable...or should i move that up into the action performed method???

About F2, its one of the lame requirements that we have

TIA


Yes. What is happening is that setEditable(false) call is being called when you run the program. The actionPerformed block is the only thing that gets executed on the action. So when you click on the context menu action, it doesn't touch anything but the code in the event block.
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Gregg: I tried moving the setEditable(false) into the actionPerformed method as the last statement to be executed and now i just can't edit it...although i get the popup...hmmm its as though even before i can start editing the tree is being set back to non-editable...
I have this entire piece of code in the mouseReleased method, if that helps.
Sudhakar Krishnamurthy
Ranch Hand

Joined: Jun 02, 2003
Posts: 76
Anyone knows how to get around this??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

ramswaroop ram,
Your post was moved to a new topic.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
Don't get me started about those stupid light bulbs.
 
subject: JTree Node Edit only from Popup menu