Home > Java > javaTutorial > body text

Example analysis of two methods in Java to realize centered display of form

黄舟
Release: 2017-07-24 14:31:35
Original
1352 people have browsed it

Method 1:

//setSize(300, 200);
pack();
// 得到显示器屏幕的宽、高
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
// 得到窗体的宽、高
int windowsWidth = this.getWidth();
int windowsHeight = this.getHeight();
//System.out.println(windowsWidth+","+windowsHeight);
        this.setBounds((width - windowsWidth) / 2,(height - windowsHeight) / 2, windowsWidth, windowsHeight);
Copy after login

Method 2:

setLocationRelativeTo(null);
Copy after login


The above is the detailed content of Example analysis of two methods in Java to realize centered display of form. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template