当前位置: 首页 > news >正文

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

 

转载于:https://www.cnblogs.com/TLightSky/p/3173899.html

相关文章:

  • /dev/VolGroup00/LogVol00:unexpected inconsistency;run fsck manually
  • 【转】设计模式介绍
  • 将asi-http-request引入到ARC工程需要做的 转
  • 【Android开发坑系列】之Fragment
  • WPF中Visible设为Collapse时,VisualTreeHelper.GetChildrenCount为0
  • 这次逻辑通了,
  • PIX8.0双链路***和上互联网流量分开且线路冗余测试
  • ie,你还能再浪一点不
  • C# params参数的应用
  • SSH2实现数据库和界面的分页
  • 总结2
  • 单点登录-利用HttpModuler实现WEB程序同一时间只让一个用户实例登陆(修改)
  • Spring IOC 和 DI 理解
  • SQL Server 2008数据备份与还原(操作篇)
  • jQuery EasyUI学习资料汇总
  • 8年软件测试工程师感悟——写给还在迷茫中的朋友
  • Angular2开发踩坑系列-生产环境编译
  • C++入门教程(10):for 语句
  • ERLANG 网工修炼笔记 ---- UDP
  • express如何解决request entity too large问题
  • iBatis和MyBatis在使用ResultMap对应关系时的区别
  • JavaScript-Array类型
  • JavaScript标准库系列——Math对象和Date对象(二)
  • k8s如何管理Pod
  • miaov-React 最佳入门
  • Shadow DOM 内部构造及如何构建独立组件
  • UMLCHINA 首席专家潘加宇鼎力推荐
  • Vue UI框架库开发介绍
  • windows-nginx-https-本地配置
  • 表单中readonly的input等标签,禁止光标进入(focus)的几种方式
  • 从零开始的无人驾驶 1
  • 基于HAProxy的高性能缓存服务器nuster
  • 快速构建spring-cloud+sleuth+rabbit+ zipkin+es+kibana+grafana日志跟踪平台
  • 前端
  • 日剧·日综资源集合(建议收藏)
  • 小程序滚动组件,左边导航栏与右边内容联动效果实现
  • 用Python写一份独特的元宵节祝福
  • python最赚钱的4个方向,你最心动的是哪个?
  • 曜石科技宣布获得千万级天使轮投资,全方面布局电竞产业链 ...
  • ​RecSys 2022 | 面向人岗匹配的双向选择偏好建模
  • # centos7下FFmpeg环境部署记录
  • # 透过事物看本质的能力怎么培养?
  • (1)(1.8) MSP(MultiWii 串行协议)(4.1 版)
  • (145)光线追踪距离场柔和阴影
  • (3)nginx 配置(nginx.conf)
  • (ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY)讲解
  • (二)Pytorch快速搭建神经网络模型实现气温预测回归(代码+详细注解)
  • (六)vue-router+UI组件库
  • (亲测)设​置​m​y​e​c​l​i​p​s​e​打​开​默​认​工​作​空​间...
  • (三)mysql_MYSQL(三)
  • (原+转)Ubuntu16.04软件中心闪退及wifi消失
  • (转)IIS6 ASP 0251超过响应缓冲区限制错误的解决方法
  • *setTimeout实现text输入在用户停顿时才调用事件!*
  • . NET自动找可写目录
  • .NET 4 并行(多核)“.NET研究”编程系列之二 从Task开始