Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree Node Edit only from Popup menu

 
Sudhakar Krishnamurthy
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone knows how to get around this??
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ramswaroop ram,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic