zoukankan      html  css  js  c++  java
  • swing让窗体垂直居中的办法

    方式一:

    核心代码

    this.setLocationRelativeTo(null);

    方式解读:这段代码在初始化控件时,设置该控件相对其他控件为null,也就是不相对其他控件显示,居中显示在屏幕上,此方法比较简单;

    方式二:

    核心代码:

       // 得到显示器屏幕的宽高
        public int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        public int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        // 定义窗体的宽高
        public int windowsWedth = 500;
        public int windowsHeight = 500;
    
        public AppWindows() {
            // 设置窗体可见
            this.setVisible(true);
            // 设置窗体位置和大小
            this.setBounds((width - windowsWedth) / 2,
                    (height - windowsHeight) / 2, windowsWedth, windowsHeight);
        }
    ————————————————
    版权声明:本文为CSDN博主「追到乌云的尽头找太阳」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/chen15369337607/article/details/82019750

    方式解读:通过获取屏幕的大小计算屏幕大小与控件大小的关系来让控件居中显示;
    最后附上自己写的java swing 程序:

     

     转自:https://blog.csdn.net/chen15369337607/article/details/82019750

  • 相关阅读:
    django项目环境搭建备忘
    Python IDE的选择和安装
    MAC上python环境搭建
    hadoop1.2.1+hbase0.90.4+nutch2.2.1+elasticsearch0.90.5配置(伪分布式)
    ubuntu下hadoop完全分布式部署
    ubuntu下集群设置静态ip
    C语言调用库函数实现生产者消费者问题
    poj 1703(带权并查集)
    poj 1330
    poj1724
  • 原文地址:https://www.cnblogs.com/wwssgg/p/14494023.html
Copyright © 2011-2022 走看看