• Post Reply Bookmark Topic Watch Topic
  • New Topic

closing JDialog when focus is lost

 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an applet that has a button that launches JDialog. If I press a button once, launch JDialog, click outside of launched JDialog and click a button again, I have 2 JDialogs. I was looking for a way to work around this as follows:
class myDialog extends JDialog implements FocusListener{
public myDialog(){
addFocusListener(this);
}
public void focusGained(FocusEvent fe){}
public void focusLost(FocusEvent fe){
this.dispose()
}
} // class
But, this does not close JDialog when it looses focus. I also tried to put this in public void init(), but no result.
thanks,
Alex
 
Sanjeev Kaushik
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the modal dialog box. Which means that when the dialog box is active, you can not go the parent window, without taking action on dialog box. When this is closed then only you can do something in the parent window.
class MyDialog extends JDialog {
public MyDialog(Frame f, String title, boolean b){
super(f,title,b);// b should be "true"
}
}

Hope this helps you.

Sanjeev Kaushik
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super(f,title,b);
This JDialog is called by a parent applet:
MyDialog md = new MyDialog(<some parameters> ;
what do I put for Frame f?
- Alex
 
Alex Kravets
Ranch Hand
Posts: 476
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plus, my parent is not a JFrame, but an applet and in API it says owner = frame.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!