JFrame centralizado

Pessoal como posso fazer para um JFrame iniciar no centro da tela?

[editado] setLocationRelativeTo( null );

Após 2 Minutos utilizando a busca.
Veja o codigo do metodo centralizeFrame

:arrow: http://www.guj.com.br/posts/list/0/547.java#2562

:thumbup:

Olá Pessoal,

Primeiro, Daniel, eu não achei o método:

:?
Segundo, tenho um método aqui é infalível:

[code] public void centerWindow(Component frame)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();

	if ( frameSize.width > screenSize.width )
		frameSize.width = screenSize.width;
	
	if ( frameSize.height > screenSize.height )
		frameSize.height = screenSize.height;
	
	frame.setLocation ( (screenSize.width - frameSize.width ) >> 1, (screenSize.height - frameSize.height) >> 1 );
}[/code]

E no contrutor, eu chamo normalmente:

Eu sempre usei e deu certinho.

Abraçoss :slight_smile:

Ops, errei:

setLocationRelativeTo( null );

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Window.html#setLocationRelativeTo(java.awt.Component)

Agora sim.
Esse método é bom mesmo, hein?!?!

Então é melhor usar o método do Daniel, do que esse gigante que coloquei.
Valeu mesmo.
Abraçoss.

Valeu !!!