Are you extending JFrame
? Don't.
Also when you inherit JFrame
, the CLOSE operation gets defined for every
window you create, so it will cause termination of window.
I din't had any issues with the following code :
JFrame j1=new JFrame();
JFrame j2=new JFrame();
JFrame j3=new JFrame();
j1.setVisible(true);
j2.setVisible(true);
j3.setVisible(true);
j1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
j2.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
j3.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
EDIT:
"Where should i type this"
Where ever it suits you.What I can think(from your closing problem) you are having as structure something like :
public class FooClass extends JFrame {
FooClass()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[]) {
new FooClass().setVisible(true);
new FooClass().setVisible(true);
new FooClass().setVisible(true);
}
}
Don't force your class to extend JFrame
, rather create the object as shown above
And use '.' operator to preform functions JSomeObject.SetThis...();
EDIT 2:
Or just see if setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE)
helps you.
OR
You can add a window listener and call setVisible(false)
on JFrame
:
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
setVisible(false);
}
});