Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus on JDialog lost

 
Frank Thompson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9279
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank Thompson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic