This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes Focus on JDialog lost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus on JDialog lost" Watch "Focus on JDialog lost" New topic
Author

Focus on JDialog lost

Frank Thompson
Greenhorn

Joined: Dec 17, 2003
Posts: 2
Hi, I am having a problem to keep the focus on a JDialog and I hope someone could help me.
My application opens a form in a JDialog, but whenever the user clicks outside the application in another program, and go back to the application using the Windows task bar, I can only see the application(on which I cannot interract), not the JDialog.
I am using the following constructor for my JDialog:
public Employe(Frame owner, String title, boolean modal, int noEmploye) {
super(owner,title,modal);
setResizable(false);
setNoEmploye(noEmploye);
refresh();
setVisible(true);
}
And I call it using:
Employe emp = new Employe(this,"",true,noEmploye);
Am I doing something wrong? If not, how do I ensure my JDialog will keep the focus when changing applications?
Thank you very much!
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8876
    
    8

I think your expectations for a modal dialog are a little high. A modal dialog will only block input to its owner frame. It won't block access to other applications.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Frank Thompson
Greenhorn

Joined: Dec 17, 2003
Posts: 2
Hi, thanks for the answer. Maybe I wasn't clear, I don't mean to prevent the user to go to other applications, but rather that when the user comes back to my application, that the Dialog be on top instead of the owner frame.
I hope this is clearer
Thanks in advance!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It really *should* be working if you are passing in the owner correctly. Is something happening like your current class extends JFrame, but the actual visible JFrame is another JFrame instance?

You can also try out the code below and see the differences between launching a dialog using the actual parent frame and other references. Just to make sure there are no OS, JDK version, etc. problems...



-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
wood burning stoves
 
subject: Focus on JDialog lost