jespersahner
asked on
Using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) with multiple JFrame's
Hi!
I am running an application which uses multiple JFrame's running in separate threads. To close a JFrame I have set:
setDefaultCloseOperation(J Frame.EXIT _ON_CLOSE) ;
The problem now is, that closing one JFrame closes all JFrame's, and I only want to close the selected JFrame.
How do I solve that?
Regards,
Jesper
I am running an application which uses multiple JFrame's running in separate threads. To close a JFrame I have set:
setDefaultCloseOperation(J
The problem now is, that closing one JFrame closes all JFrame's, and I only want to close the selected JFrame.
How do I solve that?
Regards,
Jesper
An example:
JFrame fr ; // global
.
.
WindowListener l = new WindowAdapter()
{
public void windowClosing( WindowEvent evt )
{
// close here
fr.setVisible( false ) ;
// or fr.destroy() ; <-- probably the best one to use
}
} ;
fr.addWindowListener( l ) ;
JFrame fr ; // global
.
.
WindowListener l = new WindowAdapter()
{
public void windowClosing( WindowEvent evt )
{
// close here
fr.setVisible( false ) ;
// or fr.destroy() ; <-- probably the best one to use
}
} ;
fr.addWindowListener( l ) ;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i.e.
setDefaultCloseOperation(J Frame.DISP OSE_ON_CLO SE);
setDefaultCloseOperation(J
Oh. That's easier :)
ASKER
->CEHJ: Thanks! Reading the manual often solves the problem, which I didn't in this case :-))
ASKER
-> InteractiveMind: Thanks for your input anyway :-)
:-)
Generally, you'd just add a WindowListener to your JFrame, and then either destroy() it, or hide it using setVisible(false).