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态,这样是不对的。

  • 相关阅读:
    甲午年总结
    浅谈数字营销
    机器学习笔记
    上海GDG活动有感
    我也谈谈游戏
    CSS3新增属性
    js事件详解
    DOM与BOM相关操作
    JS基础知识
    js数据类型
  • 原文地址:https://www.cnblogs.com/TLightSky/p/3173899.html
Copyright © 2011-2022 走看看