Netbean: how to resize the UI Window to screen Size

1.6k views Asked by At

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);
            }
        });
    }
2

There are 2 answers

0
Andrew Thompson On BEST ANSWER

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.
0
GartY On
private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
     this.setExtendedState(this.getExtendedState()|JFrame.MAXIMIZED_BOTH);
}   

You Only need to do this.