Yossale
Yossale

Reputation: 14361

(SWING) Menu bar actions and state keeping

I'm writing a client app that's a bit similar to MS Excel - It has one menu bar , and you have several inner frames , each frame is a file in one of several states.

The basic flow is this : After opening a file , you can click on build , and after the build is completed you can export/save it (others scenarios are more complex).

What I'm interested in is how to change the state of the menu buttons every time you switch between frames: if you haven't pressed the "build" yet , the "export" should be disabled , but if you switch to a window where you've already pressed the "build" button and it's built , the "export" button should be enabled.

Is there a design pattern for handling something like this? Any Best Known Methods?

Upvotes: 0

Views: 272

Answers (1)

JB Nizet
JB Nizet

Reputation: 692231

Add an InternalFrameListener to every internal frame you create, and listen for internalFrameActivated events. The event contains the frame which has been activated. Ask this internal frame its state, to know if it has been built, and enable/disable the menu items accordingly.

Upvotes: 1

Related Questions