• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binding JTree Node to JTextField

 
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
So I have a JTree with a bunch of nodes/leaves. For most of the leaves I can double click to open a form which represents an Object. I have an Object called NodeModel which holds a reference to my Object being edited in the form.

The name of the Object is populated in a JTextField. I have a context menu on the JTree and one of the options is 'Rename'. When I rename the node in the tree (which via code is renaming the name property of the Object) I want the JTextField that references the same name property to be updated. Conversly I would like it so that if I update the name property via the form's JTextField, the node in the tree is updated.

I'm not real clear on how I should go about this. Thanks.
[ July 29, 2008: Message edited by: Gregg Bolinger ]
 
Sheriff
Posts: 22783
131
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
Perhaps the observer pattern may help you? The object can be an observable, and both the node and the text field will be the observers.

This is actually why I hate Sun's approach to this pattern. Observable is not an interface but a regular class. They should have made it an interface and created an abstract class AbstractObservable.
 
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 Rob Prime:
Perhaps the observer pattern may help you? The object can be an observable, and both the node and the text field will be the observers.

This is actually why I hate Sun's approach to this pattern. Observable is not an interface but a regular class. They should have made it an interface and created an abstract class AbstractObservable.



Yea, I looked into that but that really jacks up my domain model because it isn't Swing specific. I'm trying to avoid much more than the crappy PropertyChangeSupport that I have to use for something like this that I am doing.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic