如何设置 JFrame 的最小尺寸并让它根据框架厚度进行调整? [英] How do I set the minimum size of a JFrame and get it to adjust for frame thickness?

查看:24
本文介绍了如何设置 JFrame 的最小尺寸并让它根据框架厚度进行调整?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个程序并在多个操作系统上处理它.Windows 10 和 Windows 7.当我为 Windows 10 或 Windows 7 正确设置最小大小时,它适用于该操作系统,但会弄乱另一个操作系统.有没有办法让 setMinimumSize 调整边框厚度?或者有没有办法获得该操作系统上边框的厚度?或者有没有办法将 JFrame 的最小大小设置为它打开时的大小?任何帮助表示赞赏.谢谢.

I am building a program and working on it on multiple operating systems. Windows 10 and Windows 7. When I set the minimum size correctly for one either Windows 10 or Windows 7 it works for that OS but messes up the other OS. Is there a way to get the setMinimumSize to adjust for border thickness? Or is there a way to get the thickness of the border on that OS? Or is there a way to get set the minimum size of the JFrame to the size it is when it opens? Any help is appreciated. Thanks.

推荐答案

不要设置最小尺寸.布局管理器的工作是确定组件的大小.布局管理器将在所有操作系统上完成其工作.

Don't set the minimum size. It is the job of the layout manager to determine the size of a component. The layout manager will do its job on all OS.

您需要做的就是将组件添加到面板/框架中,然后使用:

All you need to do is add the components to your panel/frame and then use:

frame.pack();
frame.setVisible();

pack() 方法调用布局管理器,以便所有组件的大小都正确.

The pack() method invokes the layout manager so all the components will be sized properly.

阅读 Swing 教程中关于布局管理器的部分有关更多信息和工作示例.我建议您将教程加入书签以获取所有 Swing 基础知识的教程.

Read the section from the Swing tutorial on Layout Managers for more information and working examples. I suggest you bookmark the tutorial for tutorial all the Swing basics.

我不希望用户能够将框架的大小设置为低于特定大小.

i don't want the user to be able to set the size of the frame below a certain size.

当应用程序告诉我可以制作多小(大)框架时,这非常烦人.桌面是我的空间,如果我想让它变小(变大)那你就不用管了.如果我缺少信息,我可以稍后使框架更大(更小).您的框架设计应该灵活以允许调整大小.

It is extremely annoying when an application tells me how small (large) I can make the frame. The desktop is my space, if I want to make it smaller (larger) then you should not care. I can then make the frame larger (smaller) later if I am missing information. Your frame design should be flexible to allow resizing.

在任何情况下,您都可以通过执行以下操作来设置最小值:

In any case you can set the minimum by doing something like:

frame.pack();
frame.setVisible();
frame.setMinimumSize( frame.getSize() );

这篇关于如何设置 JFrame 的最小尺寸并让它根据框架厚度进行调整?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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