Home >Java >javaTutorial >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!