这就是我用的JFrame在屏幕上,它只需检索显示器的高度和宽度,然后对框架进行中心设置。public static void moveToCenterScreen(JFrame frame) {
Toolkit kit = frame.getToolkit();
GraphicsDevice[] gs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
Insets in = kit.getScreenInsets(gs[0].getDefaultConfiguration());
Dimension d = kit.getScreenSize();
int max_width = (d.width - in.left - in.right);
int max_height = (d.height - in.top - in.bottom);
frame.setLocation((int) (max_width - frame.getWidth()) / 2, (int) (max_height - frame.getHeight() ) / 2);}