//居中设置
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
int x = (screenSize.width - frame.getWidth())/ 2;
int y= (screenSize.height - frame.getHeight())/ 2;
frame.setLocation(x , y);
JDK1.4后提供方法,建议使用
frame.setLocationRelativeTo(owner);
如果是主窗体,则
frame.setLocationRelativeTo(null);
JFrame居中
时间: 2024-11-02 15:32:48