I did it this way:
public static void showOnScreen(Window frame) {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices();
final GraphicsDevice frameDevice = frame.getParent().getGraphicsConfiguration().getDevice();
for (GraphicsDevice graphicsDevice : gd) {
if (frameDevice.equals(graphicsDevice) || frameDevice.getIDstring().equals(graphicsDevice.getIDstring())) {
final Rectangle monitorBounds = graphicsDevice.getDefaultConfiguration().getBounds();
final int x = monitorBounds.x + (monitorBounds.width - frame.getWidth()) /2;
final int y = monitorBounds.y + (monitorBounds.height - frame.getHeight()) / 2;
frame.setLocation(x, y);
}
}
}
The code searches for the device the parent of the given frame uses. It then centers the frame on that specific monitor.
I only tested this code in a dual monitor configuration.