java 如何将 jframe 的大小调整为 netbeans 中的屏幕分辨率?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15198291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resize the jframe to the screen resolution in netbeans?
提问by Vaibhav Aralkar
I am trying to develop application using swings in netbeans. So I want to resize my application frame to the screen resolution. Kindly help me out in this problem.
我正在尝试使用 netbeans 中的 swings 开发应用程序。所以我想将我的应用程序框架调整为屏幕分辨率。请帮我解决这个问题。
回答by Rob
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
// If you want to always keep the frame at this size
frame.setResizable(false);
Here is a very simple example of it, may be a good start for your application :
这是一个非常简单的示例,可能是您的应用程序的良好开端:
import javax.swing.JFrame;
public class MyFrame
{
private JFrame frame;
public MyFrame()
{
frame = new JFrame();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setVisible(true);
frame.setResizable(false);
}
public static void main(String[] args)
{
new MyFrame();
}
}
回答by gprathour
You can get it done by the following one line code
您可以通过以下一行代码完成
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());