• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

JTree Node Edit only from Popup menu

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone knows how to get around this??
 
Sheriff
Posts: 22769
130
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ramswaroop ram,
Your post was moved to a new topic.
 
Grow your own food... or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic