zoukankan      html  css  js  c++  java
  • Swing手动进行最大化最小化

    首先jdk的setExtendedState是有bug的,需要先重载JFrame的setExtendedState方法

        /**
         * Fix the bug "jframe undecorated cover taskbar when maximized". See:
         * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4737788
         *
         * @param state
         */
        @Override
        public void setExtendedState(int state) {
    
            if ((state & java.awt.Frame.MAXIMIZED_BOTH) == java.awt.Frame.MAXIMIZED_BOTH) {
                Rectangle bounds = getGraphicsConfiguration().getBounds();
                Rectangle maxBounds = null;
                // Check to see if this is the 'primary' monitor
                // The primary monitor should have screen coordinates of (0,0)
                if (bounds.x == 0 && bounds.y == 0) {
                    Insets screenInsets = getToolkit().getScreenInsets(getGraphicsConfiguration());
                    maxBounds = new Rectangle(screenInsets.left, screenInsets.top, bounds.width - screenInsets.right - screenInsets.left
                            , bounds.height - screenInsets.bottom - screenInsets.top);
                } else {
                    // Not the primary monitor, reset the maximized bounds...
                    maxBounds = null;
                }
                super.setMaximizedBounds(maxBounds);
            }
            super.setExtendedState(state);
        }
    

      

    然后,最大化的时候就设置:

    setExtendedState(Frame.MAXIMIZED_BOTH);

    但是,最小化的时候,需要注意,设置成:

    super.setExtendedState(Frame.ICONIFIED | getExtendedState());

    否则,假如直接设置:super.setExtendedState(Frame.ICONIFIED);

    还原的时候Sate在~Frame.ICONIFIED之后成了0,就变成了NORMAL态,这样是不对的。

  • 相关阅读:
    使用Selenium对付一个点击游戏
    使用Selenium登录新浪微博
    LeetCode题解 #155 Min Stack
    LeetCode题解 #2 Add Two Numbers
    django for monkey(chapter one)
    Django,数据模型创建之数据库API参考(转载)
    python djang suit模板
    Jmeter多机并发压测IP地址问题
    Jmeter进行数据库压测
    fiddler实现手机端抓包(代理)
  • 原文地址:https://www.cnblogs.com/TLightSky/p/3173899.html
Copyright © 2011-2022 走看看