Skip to main content

UI State Management

1 reply [Last post]
Joined: 2006-02-17

I have a question on the state management. I do not see how could be easily manage the UI state in J2SE/Swing. For example, when I click the a tree node, the menu should be changed, some menu item is disabled and some menuitem is removed. When the focus moved to other tree node, the menu changed again based on the context. For my application, there could be more than 20 different states there and need to adjust menu/toolbar correspondently. So based on each state to disable/hide menu in hardcoding is really not a decent way.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-11

If the states are beyond or besides the capabilities of the GUI models, create your own classes to describe the state. Listens to UI gesture events and let the event handlers operate on the state models. Let these models fire events that describe the state changes, for example ChangeEvents, PropertyChangeEvents, or custom events. Finally let your views listen to these state change events to modify the views, for example to enable or disable a menu item, to let a view change handler rebuild a menu, etc.

In case of menu items, it is good practice to build these using Swing Action instances; then enable and disable the Actions, not the menu items.

Hope this helps,