Simpler way to center frame on screen.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 11 Jul 2022 19:02:57 +0000 (22:02 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 11 Jul 2022 19:02:57 +0000 (22:02 +0300)
src/main/java/eu/svjatoslav/commons/gui/dialog/ExceptionDialog.java

index d56db29..32974f1 100755 (executable)
@@ -42,15 +42,7 @@ public class ExceptionDialog {
         frame.setSize(800, 600);
         frame.setVisible(true);
         frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
-
-        centerFrameOnScreen(frame);
-    }
-
-    private void centerFrameOnScreen(JFrame frame) {
-        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-        frame.setLocation(
-                (screenSize.width - frame.getWidth()) / 2,
-                (screenSize.height - frame.getHeight()) / 2);
+        frame.setLocationRelativeTo(null); // center frame on screen
     }
 
     private TextArea getStackTraceView(Throwable cause) {