code: public static void centerDialog(JDialog dialog) {
      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension frameSize = dialog.getSize();
      dialog.setLocation(screenSize.width / 2 - frameSize.width / 2,
              screenSize.height / 2 - frameSize.height / 2);
      dialog.setLocationByPlatform(true);
    }
docs: Set dialog location to the center of the screen
  
  @param dialog the dialog which will be centered
  @since 2.6