This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

trapping mouse and keyboard events from a modal dialog

 
Ranch Hand
Posts: 251
  • 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?
 
Bartender
Posts: 825
5
Python Ruby Java
  • 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: 251
  • 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: 251
  • 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.
 
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.

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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.
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!