• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

trapping mouse and keyboard events from a modal dialog

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

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rob Camick's Disabled Panel and Disabled Glass Pane were designed for exactly this requirement.
reply
    Bookmark Topic Watch Topic
  • New Topic