1
Use Window#setLocationRelativeTo()
passing the value null
as argument. According to the documentation:
If the Component is
null
, or theGraphicsConfiguration
Associated with this Component isnull
, the window is placed in the center of the screen.
You can call this method after the initComponents
generated by Netbeans.
public class MinhaClasse extends JFrame {
public MinhaClasse(){
initComponents(); // Método gerado pelo NetBeans.
meujFrame.setLocationRelativeTo(null);
}
}
An addendum should be called after the window has been completely built. Preferably, before setting as visible.
– user28595
So called after
initComponents
.– Renan Gomes
'Cause I usually leave it to
main
do this(after the class has become standard) as a precaution.– user28595
Is there any way to use this same code in a @Renan method?
– Fabricio Cardoso