File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus on JDialog lost" Watch "Focus on JDialog lost" New topic

Focus on JDialog lost

Frank Thompson

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) {
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

Joined: Oct 29, 2001
Posts: 9189

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.

[How To Ask Questions On JavaRanch]
Frank Thompson

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

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...

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Focus on JDialog lost
It's not a secret anymore!