It has been quite some time since I used this :

Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();
MainFrame mainFrame = new MainFrame();
int halfWidth = mainFrame.getWidth() / 2;
int halfHeight = mainFrame.getHeight() / 2;
mainFrame.setLocation(SCREEN_SIZE.width / 2 - halfWidth, SCREEN_SIZE.height / 2 - halfHeight);
mainFrame.setVisible(true);

Example for a Frame.

And apparently, you can use this one line instead:

mainFrame.setLocationRelativeTo(null); // or 'this' to parent

damn :D