Help in AWT/Swing - Display a JFrame in the center of the screen

How do I display a JFrame in the middle of the screen?I am new to standalone java GUI
[99 byte] By [Seifera] at [2007-10-2 20:10:27]
# 1
frame.setLocationRelativeTo(null);
ajneoa at 2007-7-13 22:51:02 > top of Java-index,Java Essentials,Java Programming...
# 2

JFrame.setLocation(int x, int y);

oooor

Toolkit tool = Toolkit.getDefaultToolkit();

int width=tool.getScreenSize().getWidth();

int length=tool.getScreenSize().getLength();

JFrame.setLocation(length/2-((JFrame.getSize()).getLength()/2),width/2-((JFrame.getSize()).getLength()/2))

shaishaishaia at 2007-7-13 22:51:02 > top of Java-index,Java Essentials,Java Programming...
# 3
> How do I display a JFrame in the middle of the> screen?> > I am new to standalone java GUIOk Got It! Thanks man. And sorry, I wish I could delete my post so I dont waste other people's time.
Seifera at 2007-7-13 22:51:02 > top of Java-index,Java Essentials,Java Programming...
# 4

> [code]Toolkit tool = Toolkit.getDefaultToolkit();

> int width=tool.getScreenSize().getWidth();

> int length=tool.getScreenSize().getLength();

> JFrame.setLocation(length/2-((JFrame.getSize()).getLen

> gth()/2),width/2-((JFrame.getSize()).getLength()/2))[/

> code]

You should really take a look at setLocationRelativeTo(null);

Kaj

kajbja at 2007-7-13 22:51:02 > top of Java-index,Java Essentials,Java Programming...
# 5
Thanks for this post, it really helped me. The setLocationRelative(null) is really useful, but if you're looking for a more precise result, the Toolkit way is the way to go.
keseldudea at 2007-7-13 22:51:02 > top of Java-index,Java Essentials,Java Programming...