Centering a window on the screen

Hello

I'm wondering how I can center a window on any screen no matter what its size or resolution. This is the code I've tried, but it doesn't work perfectly. It changes the window's size and no matter what value you divide it by it wont go in the center.

Toolkit theKit = this.getToolkit();

Dimension wndSize = theKit.getScreenSize();

this.setBounds(wndSize.width/3, wndSize.height/3, //Position

wndSize.width/5, wndSize.height/5); //Size

Please help me. I'm a n00b to Java by the way :)

[536 byte] By [Havelock] at [2007-9-27 21:13:36]
# 1
something like :Toolkit theKit = this.getToolkit();Dimension wndSize = theKit.getScreenSize();this.setBounds(wndSize.width/2-this.getWidth()/2, wndSize.height/2-this.getHeight/2, this.getWidth(), this.getWidth()); Didn't try it though...
kurisu1 at 2007-7-7 3:06:35 > top of Java-index,Archived Forums,Java Programming...
# 2
Thanks. It worked. You were just missing two brackets at:wndSize.height/2-this.getHeight/2Should be:wndSize.height/2-this.getHeight()/2:)Thanks again.
Havelock at 2007-7-7 3:06:35 > top of Java-index,Archived Forums,Java Programming...