gpt4 book ai didi

java - 无法为 JFrame 设置最大大小(在 Windows 下)

转载 作者:行者123 更新时间:2023-12-04 08:20:27 25 4
gpt4 key购买 nike

我试图限制 JFrame 的最大大小.然而,这仅适用于 Linux .在 Windows 下,JFrame可以自由调整大小。代码非常简单:

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();
}
}

最佳答案

来自 javadoc方法 setMaximizedBounds

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.


虽然 JFrame扩展 java.awt.Component它与 JPanel 不同, 例如。你会注意到它的父类(super class), java.awt.Window , 覆盖方法 setMinimumSize .类(class) Window与主机操作系统的窗口管理器交互。因此限制了 Window 的最大大小需要该窗口管理器支持。在Windows平台上,这似乎不是一件简单的事情。我只能找到一个旧的第三方实用程序,它允许您为所有窗口配置最大大小。引用此网页: Change The Maximum Window Size从近七年前。

关于java - 无法为 JFrame 设置最大大小(在 Windows 下),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65524291/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com