• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

[JTree]Block event?

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've got a problem. In fact, i have a JFrame with on the left a JTree and on the right some JEditorPane and 3 JButton (New, Save, Cancel).
When I clic on a JTree's Node, my JEditorPane are updated with desirated info.

I would like when i clic on JButton New, it is impossible to click on another Node in the Jtree: to block the Jtree or block event on Jtree.
I've tried but my CellRenderer applied to the JTree disappears ...
I've also tried but it doesn't work.
If someone have a idea
ThanX !
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... it sounds like you want to do the following...

The user clicks nodes of the tree, data represented by the node appears in the panel to the right. If the user clicks "New" they are adding new data to the tree, but it doesn't create a node in the tree until the user hits "Save". If the user hits "Cancel" during this process the data is not saved and a corresponding node does not appear in the tree. The user should not click on a node and have data appear during the editing process because there is no way to get back to the new data they were editing.

My suggestion would be have the "New" button set some boolean (I'm calling it "editing") to true. Have either the listener of the nodes or the method that updates your fields make sure that editing==false before it sets the data in your fields. Have "Save" and "Cancel" Buttons reset editing to false.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!