Feb 11, 2012

[Netbeans] center a JFrame window

1. JFrame properties (right click on JFrame --> properties)
2. code tab  -->  Form size policy --> Generate resize code
3. be sure "Generate center" is checked.
4. close


without GUI,

    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new BabyZoo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Display the window.
        frame.pack();
frame.setLocationRelativeTo(null);   //center the window
        frame.setVisible(true);
    }

1 comment: