File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes trapping mouse and keyboard events from a modal dialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "trapping mouse and keyboard events from a modal dialog" Watch "trapping mouse and keyboard events from a modal dialog" New topic
Author

trapping mouse and keyboard events from a modal dialog

Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
I have a sub-dialog in my application that calculates some parameters, which the user can decide to accept or ignore. The calculation of the parameters takes about 10 seconds, so I tried to put up a wait cursor and disable keyboard and mouse input until it finishes. The wait cursor comes up fine, but I can click on buttons or type in text fields while the wait cursor is up and the actions occur once the calculation finishes.

Here is a simplified version of what I tried-





I thought if the glass pane was visible and I had mouse and key listeners that ignored input, then the user would not be able to interact with the dialog. But that is not quite the case. You can hit the done button while the calculation is running and the dialog dismisses as soon as the calculation is finishes. Or you can click in the text field and then type text and it shows up once the calculation finishes.

Could someone set me straight on how one is supposed to handle this situation?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

Why don't you just disable components you don't want user to be able to use while the task is finished and then enable them back once it's done?


The quieter you are, the more you are able to hear.
Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
From what I read, it seemed like the 'standard' approach when you don't want a dialog to have user interaction is to put a glass plane over it. Maybe I should try that in a regular dialog and see if I can get that working first. The advantage over disabling individual components is that I don't have to loop over every component in the dialog or change my wait routine if I change a dialog element. Needless to say, the real dialog is more complex than the example.
Jon Swanson
Ranch Hand

Joined: Oct 10, 2011
Posts: 200
The same commands just using a JFrame also successfully bring up a wait cursor, but do not stop mouse or keyboard events. So clearly I need to have that working first.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
instead of a glasspane, perhaps setting up a 'dummy' panel in a CardLayout might work better for you.

Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

Rob Camick's Disabled Panel and Disabled Glass Pane were designed for exactly this requirement.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: trapping mouse and keyboard events from a modal dialog