无法设置JFrame的最大大小(在Windows下) [英] Cannot set maximum size for JFrame (under Windows)

查看:61
本文介绍了无法设置JFrame的最大大小(在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.

尽管JFrame扩展了java.awt.Component,但它与JPanel不同.您会注意到它的超类java.awt.Window覆盖了方法setMinimumSize.类Window与主机操作系统的窗口管理器进行交互.因此,该窗口管理器需要支持限制Window的最大大小.在Windows平台上,这似乎不是一件容易的事.我只能找到一个旧的第三方实用程序,该实用程序允许您为所有窗口配置最大大小.请参阅此网页:更改最大窗口大小来自将近七年前.

Although 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.

这篇关于无法设置JFrame的最大大小(在Windows下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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