java Netbeans GUI 设计器和固定大小的应用程序面板
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/248580/
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
Netbeans GUI Designer & Fixed-Size Application Panels
提问by
I'm having a problem, creating a fixed-size overall panel for a touchscreen GUI application that has to take up the entire screen. In a nutshell, the touchscreen is 800 x 600 pixels, and therefore I want the main GUI panel to be that size.
我遇到了一个问题,为必须占据整个屏幕的触摸屏 GUI 应用程序创建一个固定大小的整体面板。简而言之,触摸屏是 800 x 600 像素,因此我希望主 GUI 面板是那个大小。
When I start a new GUI project in NetBeans, I set the properties of the main panel for min/max/preferred size to 800 x 600, and the panel within the 'Design' view changes size. However, when I launch the app, it is resized to the original default size.
当我在 NetBeans 中启动一个新的 GUI 项目时,我将最小/最大/首选大小的主面板的属性设置为 800 x 600,并且“设计”视图中的面板会更改大小。但是,当我启动应用程序时,它的大小会调整为原始默认大小。
Adding this code after initComponents() does not help:
在 initComponents() 之后添加此代码无济于事:
this.mainPanel.setSize(new Dimension(800,600));
this.mainPanel.setMaximumSize(new Dimension(800,600));
this.mainPanel.setMinimumSize(new Dimension(800,600));
this.mainPanel.repaint();
I've peeked into all of the resource files and cannot seem to find values that would override these (which seems somewhat impossible anyway, given that I'm setting them after initComponents() does its work). I'm using the FreeDesign layout, because I wanted complete control over where I put things.
我已经查看了所有资源文件,但似乎无法找到可以覆盖这些文件的值(无论如何,这似乎有点不可能,因为我是在 initComponents() 完成其工作后设置它们的)。我正在使用 FreeDesign 布局,因为我想完全控制我放置的位置。
I suspect the layout manager is resizing things based upon how many widgets I have on the screen, because different prototyped screens come in at differing sizes.
我怀疑布局管理器会根据我在屏幕上有多少小部件来调整大小,因为不同的原型屏幕有不同的尺寸。
Help is appreciated!
帮助表示赞赏!
回答by Chobicus
Have you tried java full screen mode?
你试过java全屏模式吗?
回答by Stroboskop
I'm not sure how your touchscreen device works. But if you use Netbeans preview your panel is put in some outer container like JFrame/JWindow. And just maybe you set the frame to 800x600.
我不确定您的触摸屏设备是如何工作的。但是,如果您使用 Netbeans 预览,您的面板将被放置在一些外部容器中,例如 JFrame/JWindow。也许您将框架设置为 800x600。
If so, then the problem might be that the frame eats a few pixels for its own border, leaving your panel size < 800x600. And in that case your panel will be unable to use your min/max settings and revert to default sizes.
如果是这样,那么问题可能是框架占用了自己的边框的几个像素,使面板尺寸小于 800x600。在这种情况下,您的面板将无法使用您的最小/最大设置并恢复为默认尺寸。
回答by Peter
I use this method to complete the task, not sure if its the best and you need to wait calling it until the frame is actually on the screen.
我使用这种方法来完成任务,不确定它是否最好,您需要等待调用它直到框架实际出现在屏幕上。
protected void growBig()
{
int screenWidth = java.awt.Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = java.awt.Toolkit.getDefaultToolkit().getScreenSize().height;
Rectangle rectangle = getFrame().getBounds();
rectangle.setSize(screenWidth, screenHeight);
getFrame().setBounds(0, 0, screenWidth, screenHeight);
getFrame().setSize(screenWidth, screenHeight);
getFrame().doLayout();
getFrame().validate();
updateUI();
}

