[Logo]
Forums Register Login
Binding JTree Node to JTextField
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 ]
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.
 
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.
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 19, 2017 13:11:44.