tags:

views:

29

answers:

1

I have a data model model which has a boolean flag connected, and I have a view with several components that I want to enable if model.isConnected() is true and disable if it is not. What is the best way to implement this?

+1  A: 

Have your model accept PropertyChangeListeners (perhaps by delegating to a PropertyChangeSupport). Fire a PropertyChangeEvent whenever the connected state changes. Have the components listen to that property change, and change their visual state as appropriate.

Jonathan Feinberg
when to use PropertyChangeSupport vs. SwingPropertyChangeSupport?
Jason S
Good point! I wasn't familiar with SwingPropertyChangeSupport. As long as you fire your property changes from within the event thread, you should be ok with SwingPropertyChangeSupport.
Jonathan Feinberg
hmm, what's the difference between the two?
Jason S
"This subclass of java.beans.PropertyChangeSupport is identical in functionality -- it sacrifices thread-safety (not a Swing concern) for reduce memory consumption, which helps performance (both big Swing concerns). Most of the overridden methods are only necessary because all of PropertyChangeSupport's instance data is private, without accessor methods."
Jonathan Feinberg