Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annoying quirk with JDialog on Windows 7

 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't do much Swing programming usually but I got to play with some at work recently. It's been a lot of fun but I've got this annoying little issue.

My app consists of a JFrame that opens up a modal JDialog to show progress of a long running task. When I alt-tab or switch to another window and then switch back to my program, the modal dialog comes to the top of the view but the parent JFrame does not come to the front. The parent JFrame remains behind the window I temporarily switched to while the modal JDialog comes right to the top. I expect to see JFrame come to the top along with the modal dialog.

This does not happen on my Linux/Gnome box, just on the Windows 7 boxes I have run the program on. Does anyone have any tips?
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the dialog constructed with the frame as its owner?

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.
 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspected that your question about constructing the dialog with the frame as the owner was going to lead me to the answer and it did. Thanks Darryl!
In my program, I subclassed JDialog (well actually the Eclipse WindowBuilder plugin did it for me) and didn't notice the constructors of JDialog that take a Frame as an argument.
After placing a call to the JDialog's constructor with the parent frame as an argument in my JDialog subclass's constructor, I got the behavior I expect.

Thanks!
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to know that the solution was so simple!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic