Search code examples
javaswingjframejwindow

Netbean: how to resize the UI Window to screen Size


I am developing a small application in Java using Netbeans. I use a JFrame as a base control and drag and drop all required controls over it as appropriate.

The application is working fine as expect. Now i simply want that when my application runs for the fist time the size of my Application window should be equal to the size of my screen. In simple words i want my application to be maximized when it opens. Following is the code for my main method:

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MyUI myframe = new MyUI();
                myframe.setTitle("my tiltle");
                myframe.setVisible(true);                
                //new GPrideUI().setVisible(true);
            }
        });
    }

Solution

  • See Frame.setExtendedState(int) which:

    Sets the state of this frame. The state is represented as a bitwise mask.

    • NORMAL Indicates that no state bits are set.
    • ICONIFIED
    • MAXIMIZED_HORIZ
    • MAXIMIZED_VERT
    • MAXIMIZED_BOTH Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT.