• Post Reply Bookmark Topic Watch Topic
  • New Topic

Listeners and buttons vs enabling application from background  RSS feed

 
Kenton Born
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a Java application is in the background, then clicked, this can be detected in a windowActivated() event by testing if event.getOppositeWindow() is null.

What I want is a simple way to make the first click on a background Java application not do anything but bring the application into focus (i.e. if a button is pressed, if a drawing canvas is touched, etc, nothing happens until it is done again!)


I considered throwing a transparent "cover" over everything on a WindowDeactivated() event with a mouselistener on it, making it dispose on a click. Surely there is a better way than this, though :-D

I tried disabling listeners on deactivation, and re-enabling them on activation, but they still caught the click.

Any thoughts?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That "transparent cover" idea was such a good one that the Swing designers already stole it from you.

It's called the "glass pane" and you can read about it in this part of the Swing tutorial: How to Use Root Panes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!