• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binding JTree Node to JTextField

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!