swing: best way to make components enabled/disabled depending on the state of a model
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?
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.
精彩评论