How can I have the newly open jframe have the same properties开发者_运维百科 like Size and position on screen. Thanks
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);
}
@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
精彩评论