Netbeans GUI Designer和固定大小的应用程序面板

时间:2022-03-25 02:44:57

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!

感谢帮助!

3 个解决方案

#1


1  

Have you tried java full screen mode?

你试过java全屏模式吗?

#2


0  

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();
  }

#3


0  

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。在这种情况下,您的面板将无法使用您的最小/最大设置并恢复为默认大小。

#1


1  

Have you tried java full screen mode?

你试过java全屏模式吗?

#2


0  

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();
  }

#3


0  

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。在这种情况下,您的面板将无法使用您的最小/最大设置并恢复为默认大小。