[英]Automatically Maximize Window Using Netbeans
I have been trying to get the window to automatically maximize using Netbeans. 我一直在尝试获取使用Netbeans自动最大化的窗口。
I've probably looked through 4 or 5 pages of Google for an answer. 我可能已经浏览了Google的4到5页来寻找答案。
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 我正在使用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!
预先感谢您的任何投入! :)
:)
to maximize your form at startup you have to let netbeans do it in its rigth time! 为了在启动时最大化表单,您必须让netbeans在其严格的时间内完成它! You can accomplish this through the JFrame's windowOpened event:
您可以通过JFrame的windowOpened事件来完成此操作:
In the JFrame's Properties window, click the Events button; 在JFrame的Properties窗口中,单击Events按钮;
Click the ellipsis (...) button next to the windowOpened event; 单击windowOpened事件旁边的省略号(...);
In the Handler dialog box, add a handler called formWindowOpened (as suggested by NetBeans); 在“处理程序”对话框中,添加一个名为formWindowOpened的处理程序(如NetBeans所建议);
Within the formWindowOpened method in the Source Editor, paste the following code: 在源代码编辑器的formWindowOpened方法中,粘贴以下代码:
Code: 码:
setExtendedState(JFrame.MAXIMIZED_BOTH);
Good luck! 祝好运!
Regarding setExtendedState()
, "Note that if the state is not supported on a given platform, nothing will happen." 关于
setExtendedState()
,“请注意,如果给定平台不支持该状态,则不会发生任何事情。”
If that's not relevant, an sscce may be helpful. 如果这不相关,那么使用scsc可能会有所帮助。
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
特别是,
MAXIMIZED_HORIZ | MAXIMIZED_VERT == MAXIMIZED_BOTH
MAXIMIZED_HORIZ | MAXIMIZED_VERT == MAXIMIZED_BOTH
: MAXIMIZED_HORIZ | MAXIMIZED_VERT == MAXIMIZED_BOTH
:
NORMAL 0 0000 MAXIMIZED_HORIZ 2 0010 MAXIMIZED_VERT 4 0100 MAXIMIZED_BOTH 6 0110
Just insert the code bellow 只需插入下面的代码
publicProject () { setExtendedState(MAXIMIZED_BOTH); }
Put the code below to the initComponents();
将下面的代码放入
initComponents();
public Home() {
initComponents();
this.setExtendedState(MAXIMIZED_BOTH);
}
Put the below code above initcomponents();
将以下代码放在
initcomponents();
之上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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.