ashbyp
ashbyp

Reputation: 436

Model Dialog - Swing. Blocking input to only certain parts of the UI

Scenario: I have a screen, top part of the screen is some text fields, bottom part of the window is a list.

Under certain circumstance I want to raise a modal (yes/no) dialog which will prevent the user from interacting with the top part of the window - ie: the text fields, but will still allow the user to interact with the list at the bottom of the screen.

Is it possible to create a modal dialog like this?

Upvotes: 1

Views: 442

Answers (3)

Joshua McKinnon
Joshua McKinnon

Reputation: 24719

This may or may not be useful. Java 6 introduced a new Modality API.

The granularity is at the Window level (Frames, Dialogs, ...), so depending on the definition of your "top of the screen, bottom of the screen" it may not be helpful. If you can get your components needing different modality behavior in separate frames, then this is indeed possible. If not, you probably have to fudge it.

Upvotes: 1

Andreas Dolk
Andreas Dolk

Reputation: 114807

'partially Modal' is not possible. You have to simulate the behaviour some way. Disabling the panel and all its children is one way (see DrDipshits answer) but if you don't like the widget showing the 'disabled' look, I can offer another workaround:

Render the top part into a bitmap and replace the real panel with the 'screenshot' as long as the dialog is shown. This will preserve the actual look and make the top panel unusual for the moment.

Upvotes: 1

Ultimate Gobblement
Ultimate Gobblement

Reputation: 1879

I'd write a function something like setTopPanelDisabled(boolean enabled) which then calls the setEnabled method of all the widgets in the top half of your panel. When the dialog closes you just call the method again to re-enable the widgets.

Upvotes: 1

Related Questions