NetBeans (Java Swing):设置窗口大小 [英] NetBeans (Java Swing): Set window size
问题描述
这让我发疯.当我在设计模式下为我的窗口设置合适的大小时,它只会忽略这个大小并在我编译和运行时使用其他大小.即使很难,我设置了 minimumSize 和 preferredSize 它只是忽略了这一点......为什么?如何设置自己的尺寸?
This is driving me crazy. When I set an appropriate size for my window in design-mode it just ignores this size and uses something else when I compile and run. Even tough I set the minimumSize and preferredSize it just ignores this... Why? How can I set my own size?
推荐答案
即使你用 minimumSize
和 preferredSize
设置了大小,你也可能忘记调用窗口.pack()
其中 Swing 将根据设置的大小调整组件(及其所有子组件)的大小.
Even if you've set the size with minimumSize
and preferredSize
, you might have forgotten to call Window.pack()
in which Swing will resize the components (and all of it's subcomponents) according to the sizes set.
在设置完所有首选大小后,您可以在窗口(或构建窗口的任何东西)中调用它.
You call it in your window (or whatever is building your window) after all the preferred sizes are set.
或者,您可以使用 Component.setSize()
方法但它附带一些注意事项.
这篇关于NetBeans (Java Swing):设置窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!