为什么 Netbeans 设计器将 JFrame 大小设置为与我指定的不同?

Why does the Netbeans designer set the JFrame size to something different than I specified?

在 netbeans 设计器中,我使用的每个框架和面板都设置为 [415,330],但是当我 运行 程序时,window 仍然设置为 [400,300] ] 或类似的东西。我正在更改最小、最大和首选尺寸。我需要做其他事情吗?

编辑:重新启动 netbeans,问题自行解决。

即使您使用 minimumSizepreferredSize 设置了大小,您也可能忘记调用 Window.pack(),Swing 将在其中调整组件(及其所有子组件)的大小) 根据尺寸设置。

在设置所有首选尺寸后,您可以在 window(或构建 window 的任何内容)中调用它。