问题描述
我一直试图让窗口自动最大化使用Netbeans。
I have been trying to get the window to automatically maximize using Netbeans.
我可能已经浏览了4或5页Google以获得答案。
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);
}
我使用的是Netbeans 6.9.1
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! :)
推荐答案
关于,请注意,如果状态不是在给定的平台上支持,什么都不会发生。
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();
}
});
}
}
附录:相关的状态常数似乎形成连贯的组。特别是, MAXIMIZED_HORIZ | MAXIMIZED_VERT == MAXIMIZED_BOTH
:
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
这篇关于使用Netbeans自动最大化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!