自己写的一个小方法 public static void setLocationCenter(Component component) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension compSize = component.getSize(); if (compSize.height > screenSize.height) { compSize.height = screenSize.height; } if (compSize.width > screenSize.width) { compSize.width = screenSize.width; } component.setLocation((screenSize.width - compSize.width) / 2, (screenSize.height - compSize.height) / 2); }