Jame
Jame

Reputation: 22180

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

Upvotes: 2

Views: 1836

Answers (2)

GartY
GartY

Reputation: 1

private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
     this.setExtendedState(this.getExtendedState()|JFrame.MAXIMIZED_BOTH);
}   

You Only need to do this.

Upvotes: 0

Andrew Thompson
Andrew Thompson

Reputation: 168815

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.

Upvotes: 5

Related Questions