Any body please can please help me, how to center a JFrame on Mac. OS X?
I have tried:
this.setLocationRelativeto(null);
this.setLocationRelativeto(this);
this.setLocationRelativeto(getRootPane());
..and
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Dimension screenSize = toolkit.getScreenSize();
    final int x = (screenSize.width - this.getWidth()) / 2;
    final int y = (screenSize.height - this.getHeight()) / 2;
    this.setLocation(x, y);
None of the above worked, my frame is still at the bottom and hidden behind the Mac dock.
Location should be set after you packed your frame (wich calculates size of the frame). And after that it should be made visible (it is hidden by default otherwize).
 pack();
 setLocationRelativeTo(null);
 setVisible(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With