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 ) ; }
Set dialog location to the center of the screen