Java Swing 知识回顾

Swing是java 做UI 的时侯使用比较好的控件,应用的都是java的基本知识。

1 如何让窗口更好的居中显示

   可以用下面的代码:

     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        this.getContentPane().setLayout(new BorderLayout());
        this.setPreferredSize(new Dimension(512,450));           
        int frameWidth = this.getPreferredSize().width;
        int frameHeight = this.getPreferredSize().height;
        this.setSize(frameWidth, frameHeight);
        this.setLocation((screenSize.width - frameWidth) / 2,(screenSize.height - frameHeight) / 2);
    this.setTitle("Hello Word");
 
 this.setVisible(true);
 
 this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

2

原文地址:https://www.cnblogs.com/tomcattd/p/2948370.html