How can I have the newly open jframe have the same properties like Size and position on screen. Thanks
Asked
Active
Viewed 1,077 times
2 Answers
1
If you are only interested in size and position JFrame.getBounds returns these properties:
newFrame.setBounds(oldFrame.getBounds());
public static void main(String args[]) throws Exception {
final JFrame oldFrame = new JFrame("Test");
oldFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
JFrame newFrame = new JFrame("Test");
newFrame.setBounds(oldFrame.getBounds());
newFrame.setVisible(true);
}
});
oldFrame.setSize(400, 300);
oldFrame.setVisible(true);
}

dacwe
- 43,066
- 12
- 116
- 140
-
1please amend nonExist method setPosition with ... http://download.oracle.com/javase/6/docs/api/javax/swing/JFrame.html – mKorbel May 31 '11 at 07:43
-
@mKorbel: Updated that minutes ago :) – dacwe May 31 '11 at 07:44
1
@Sam that not good idea to create new TopLevelContainer on fly, better would be reuse exist JFrame and just replace/switch its contents JPanel and if you need/want to display more TopLevelContainers then others would by JDialog(s)
please check how to LayoutManagers works (with examples there) and tons of example about Swing on Java2s.com

mKorbel
- 109,525
- 20
- 134
- 319