Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trapping mouse and keyboard events from a modal dialog

 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jon Swanson
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
instead of a glasspane, perhaps setting up a 'dummy' panel in a CardLayout might work better for you.

 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick's Disabled Panel and Disabled Glass Pane were designed for exactly this requirement.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic