开发者

swing: best way to make components enabled/disabled depending on the state of a model

开发者 https://www.devze.com 2022-12-18 06:58 出处:网络
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开发者_开发百科. Wh

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消