This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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???
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.
Joined: Jun 02, 2003
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 ]
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
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.
Joined: Jun 02, 2003
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.