Center JFrame on the screen

I've been trying to figure this out using every different example I find online, but nothing is working. I'm using version 1.4.2 so I know it's a bit different than version 1.6. Currently, when I open my application it'll open to bottom right corner of the screen at an 800x600 size. I want it at the 800x600, but I think what's happening is it is opening at 0x0 and is centered, but then is resizing to 800x600 which no longer makes it center. Since it's version 1.4.2 I can't set a prefered size either.

I've tried adding:

this.setLocationRelativeTo(null);

this.setVisible(true);

but that isn't working either.

[719 byte] By [tristanlee85a] at [2007-11-27 9:42:39]
# 1

should work OK like this

this.setSize(800,600);

//or this.pack();

this.setLocationRelativeTo(null);

this.setVisible(true);

the frame needs to be sized, prior to setLocationRelativeTo(null);

Michael_Dunna at 2007-7-12 23:46:32 > top of Java-index,Desktop,Core GUI APIs...
# 2
another way:Dimension s, c = Toolkit.getDefaultToolkit().getScreenSize();s = frame.getSize();frame.setLocation((c.width - s.width) / 2,(c.height - s.height) / 2);
Yannixa at 2007-7-12 23:46:32 > top of Java-index,Desktop,Core GUI APIs...