java怎么让预览按钮弹出的框在屏幕中间显示

2024-12-22 09:34:34
推荐回答(2个)
回答1:

try to use
JFrame.setLocationRelativeTo(Componenet);
JFrame.setLocationByPlatform(boolean locationByPlatform);
you can learn it from java api

回答2:

导入这两个包import java.awt.Dimension;import java.awt.Toolkit;
Dimension dimension=kit.getScreenSize();//获取屏幕大小
int width=dimension.width;
int height=dimension.height;
int x=(width-WIDTH)/2;
int y=(height-HEIGHT)/2;
frame.setLocation(x, y);