NetBeans (Java Swing):设置窗口大小 [英] NetBeans (Java Swing): Set window size

查看:147
本文介绍了NetBeans (Java Swing):设置窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我发疯.当我在设计模式下为我的窗口设置合适的大小时,它只会忽略这个大小并在我编译和运行时使用其他大小.即使很难,我设置了 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?

推荐答案

即使你用 minimumSizepreferredSize 设置了大小,你也可能忘记调用窗口.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆