Automatically Maximize Window Using Netbeans

孤街浪徒 提交于 2019-12-06 13:55:20

问题


I have been trying to get the window to automatically maximize using Netbeans.

I've probably looked through 4 or 5 pages of Google for an answer.

The web pages always provide something like this:

public void run() {
    MyFrame myFrame = new MyFrame();
    myFrame.setVisible(true);
    myFrame.setExtendedState(myFrame.getExtendedState() | JFrame.MAXIMIZED_BOTH);
}

I am using Netbeans 6.9.1

Does this no longer work? Is there another way to do this?

Also, if you find your answer on a web page, please provide the link so I can look into this further. Thanks in advance for any input! :)


回答1:


Regarding setExtendedState(), "Note that if the state is not supported on a given platform, nothing will happen."

If that's not relevant, an sscce may be helpful.

Addendum: This example seems to function correctly:

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;

/** @see http://stackoverflow.com/questions/5207425 */
public class NewJavaGUI extends JPanel {

    private void display() {
        JFrame f = new JFrame("NewJavaGUI");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(this);
        f.pack();
        f.setExtendedState(f.getExtendedState() | JFrame.MAXIMIZED_BOTH);
        f.setVisible(true);
    }

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

            @Override
            public void run() {
                new NewJavaGUI().display();
            }
        });
    }
}

Addendum: The relevant state constants appear to form a coherent set. In particular, MAXIMIZED_HORIZ | MAXIMIZED_VERT == MAXIMIZED_BOTH:

NORMAL          0 0000
MAXIMIZED_HORIZ 2 0010
MAXIMIZED_VERT  4 0100
MAXIMIZED_BOTH  6 0110



回答2:


to maximize your form at startup you have to let netbeans do it in its rigth time! You can accomplish this through the JFrame's windowOpened event:

In the JFrame's Properties window, click the Events button;

Click the ellipsis (...) button next to the windowOpened event;

In the Handler dialog box, add a handler called formWindowOpened (as suggested by NetBeans);

Within the formWindowOpened method in the Source Editor, paste the following code:

Code:

    setExtendedState(JFrame.MAXIMIZED_BOTH); 

Good luck!




回答3:


Just insert the code bellow

public Project () {
  setExtendedState(MAXIMIZED_BOTH);
}



回答4:


Put the code below to the initComponents();

public Home() {
        initComponents();
        this.setExtendedState(MAXIMIZED_BOTH);
    }



回答5:


Put the below code above initcomponents();:

 public Test() {
    this.setExtendedState(JFrame.MAXIMIZED_BOTH);

    this.setUndecorated(true);
    //use this command to remove the maximize,minimize,close option from the 
    //title.        

     initComponents();

 }


来源:https://stackoverflow.com/questions/5207425/automatically-maximize-window-using-netbeans

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!