• Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog Focus

 
Josh Lanierd
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a View->Settings that launches a JDialog. My problem is the JDialog is the active window and it is the windows in focus. If I switch to another window like Internet Explorer the program is hosed. The JDialog is still the active window because everything I click on the program beeps at me. The problem is it is not the window in focus. Therefore, I have to close the window through the task manager.
How do I make the JDialog come up so that if I switch from the program and then move back to the program the JDialog is in focus. Right now when I switch back to the program the JDialog is moved behind the main program and I can't get to it. If I set the focus will it make it so that when I move back to the main program the JDialog is sitting on top of the main window in an active state. I don't want the user to continue until they have performed an action.
If I am correct this is accomplised with setModal, which I did. But I can't get it to stay the active window.
Thanks for any help you can provide.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since J2SE 1.4 you can use the method setFocusableWindowState in the Window api. In the JDialog api scroll down to the Methods inherited from class java.awt.Window section to find this.
 
Josh Lanierd
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried this out and it doesn't work. My class extends JDialog and implements ActionListener. In the constructor I tried this.setFocusableWindowState(true), then right after that I call System.out.println(this.getFocusableWindowState)and it prints true. Therefore I would assume that the FocusableWindowState is true and it would be the active window, but it isn't.
It still shows up as the active window until I switch to another window and then when I try to come back the program is basically locked up because the JDialog has moved behind the main window and every time I click on the main window it beeps at me because it is waiting for feedback from the JDialog window.
Is there a way to make that call that I am missing or something?
Thanks,
Josh
 
Josh Lanierd
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured it out thanks. I extended JDialog and then sent in my JFrame. Then in my constructor in the JDialog I call super(jFrame, true);
This true makes the JDialog modal.
Josh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!