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

查看:132
本文介绍了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,您也可能忘记了调用

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天全站免登陆