tags:

views:

26

answers:

3

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?

+1  A: 

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.

DrDipshit
Could be a good workaround thanks. I'd rather replicate the behaviour of a real modal dialog which doesn't grey out components and rings the bell if you try and click on another window, but that's probably going to be too hard, so thanks again.
ashbyp
Its an ugly hack, but you could set the disabled colours of the textfields to the enabled colours. Dont know exactly how you'd get the bell to beep, but I know it can be done. I had to use a JFormatted text field for one of my assignments which makes a beep when you enter something wrong in it.Have fun.
DrDipshit
+1  A: 

'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.

Andreas_D
+1  A: 

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.

Joshua McKinnon
Cool - thanks for the link. This will probably do the trick. This kind of modality was available in the Motif tookit years ago, so good to see Java picking it up now.
ashbyp