如何在Java中使窗口小于125 x 50?
我正在尝试用 Java 创建一个 50x50 的窗口,但该窗口不会小于 125x50,即使我尝试手动调整它的大小。
这是我当前的代码:
import javax.swing.*;
public class smallwindow {
public static void main(String args[]) {
JFrame frame = new JFrame("");
frame.setSize(50, 50);
frame.setVisible(true);
}
}
我正在 Mac OS X 上使用最新版本的 Java 运行此代码。 有没有办法用 JFrame 来做到这一点,或者我需要使用其他东西,比如 AWT?
**编辑:有没有办法在保留标题栏、窗口管理按钮等的同时做到这一点?
I'm trying to create a 50x50 window in Java but the window won't go smaller than 125x50, even if I try to manually resize it.
Here's my code currently:
import javax.swing.*;
public class smallwindow {
public static void main(String args[]) {
JFrame frame = new JFrame("");
frame.setSize(50, 50);
frame.setVisible(true);
}
}
I am running this with the latest version of Java on Mac OS X.
Is there any way to do this with a JFrame, or would I need to use something else, like maybe AWT?
**edit: is there a way to do this while retaining the titlebar, window management buttons, etc.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您必须在
JFrame
上执行以下操作:You would have to do the following on the
JFrame
:伙计们,我做了更多研究,显然有一个名为
setMinimumSize
的方法基本上,您需要做的就是添加
我发现如果尺寸小于大约 75x75,则调整大小它会突然将最小宽度更改为 75 左右。解决方案就是执行
frame.setResizes(false)
但无论如何,感谢您的帮助!
Guys, I did a little more looking into it, apparently there is a method called
setMinimumSize
Basically, all you need to do is add
I've found that if the size is less than about 75x75, then resizing it will suddenly change the minimum width to around 75. The solution is to just to do
frame.setResizable(false)
But anyways, thanks for all your help!
您可以使用包含标题栏的 Metal LAF:
You can use the Metal LAF which includes the title bar: