Home >Java >javaTutorial >How to center a form in java

How to center a form in java

藏色散人
藏色散人Original
2020-05-21 10:57:153757browse

How to center a form in java

#How to center a form in java?

// 设置窗体大小
int windowsWedth = 600;
int windowsHeight = 600;
// 得到显示器屏幕的宽高
int width = Toolkit.getDefaultToolkit().getScreenSize().width;
int height = Toolkit.getDefaultToolkit().getScreenSize().height;
//设置窗体在显示器居中显示
this.setBounds((width - windowsWedth) / 2,
(height - windowsHeight) / 2, windowsWedth, windowsHeight);

This is the centering code in the program I wrote. Try it. It should work!

Recommended: "java learning"

The above is the detailed content of How to center a form in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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