无法设置JFrame的最大大小(在Windows下) [英] Cannot set maximum size for JFrame (under Windows)
问题描述
我正在尝试限制JFrame
的最大大小.但是,这仅在Linux下有效.在Windows下,JFrame
的大小可以自由调整.代码很简单:
I am trying to limit the maximum size of a JFrame
. However, this works only under Linux. Under Windows, the JFrame
is freely resized. The code is pretty simple:
public class TestMaxSize extends javax.swing.JFrame {
public TestMaxSize() {
setSize(new java.awt.Dimension(400, 400));
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximizedBounds(new java.awt.Rectangle(0, 0, 400, 400));
setMaximumSize(new java.awt.Dimension(400, 400));
setVisible(true);
}
public static void main(String args[]) {
new TestMaxSize();
}
}
推荐答案
来自
请注意,给定的最大化边界将用作本机系统的提示,因为底层平台可能不支持设置最大化窗口的位置和/或大小.在这种情况下,提供的值不会影响处于最大化状态的框架的外观.
Note, the given maximized bounds are used as a hint for the native system, because the underlying platform may not support setting the location and/or size of the maximized windows. If that is the case, the provided values do not affect the appearance of the frame in the maximized state. 尽管 Although 这篇关于无法设置JFrame的最大大小(在Windows下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
JFrame
扩展了java.awt.Component
,但它与JPanel
不同.您会注意到它的超类java.awt.Window
覆盖了方法setMinimumSize
.类Window
与主机操作系统的窗口管理器进行交互.因此,该窗口管理器需要支持限制Window
的最大大小.在Windows平台上,这似乎不是一件容易的事.我只能找到一个旧的第三方实用程序,该实用程序允许您为所有窗口配置最大大小.请参阅此网页:更改最大窗口大小来自将近七年前.JFrame
extends java.awt.Component
it is not the same as JPanel
, for example. You will notice that its superclass, java.awt.Window
, overrides method setMinimumSize
. Class Window
interacts with the window manager of the host operating system. Hence limiting the maximum size of a Window
needs to be supported by that window manager. On the Windows platform, it appears that this is not a simple thing to do. I could only find an old, third party utility that allows you to configure a maximum size for all windows. Refer to this Web page: Change The Maximum Window Size from nearly seven years ago.