Home > Java > Java Tutorial > body text

How to center a form in java

藏色散人
Release: 2020-05-21 10:57:15
Original
3582 people have browsed it

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);
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!