Este es el Ejemplo #08 del Topic: Programación Gráfica en Java.
El siguiente ejemplo presenta dos funciones, uno para centrar un JFrame en la pantalla, ésta no requiere necesariamente de un formulario padre y el otro para centrar en JInternalFrame, el cual si requiere de un formulario padre.
...
private void setCentrarJInternalFrame(JInternalFrame jifrm)
{
jifrm.setLocation(jifrm.getParent().getWidth()/2 - jifrm.getWidth()/2 ,jifrm.getParent().getHeight()/2 - jifrm.getHeight()/2 - 20);
}
private void setCentrarJFrame(JFrame jfrm)
{
jfrm.setLocationRelativeTo(null);
}
...
Código de Ejemplo:
package beastieux.gui;
import java.awt.Dialog;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
/**
*
* @author beastieux
*/
public class Ejm08_CentrarFormulario extends JFrame{
public Ejm08_CentrarFormulario()
{
this.setSize(500, 200);
setCentrarJFrame((JFrame)this);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
}
private void setCentrarJInternalFrame(JInternalFrame jifrm)
{
jifrm.setLocation(jifrm.getParent().getWidth()/2 - jifrm.getWidth()/2 ,jifrm.getParent().getHeight()/2 - jifrm.getHeight()/2 - 20);
}
private void setCentrarJFrame(JFrame jfrm)
{
jfrm.setLocationRelativeTo(null);
}
public static void main(String args[]) {
Ejm08_CentrarFormulario obj = new Ejm08_CentrarFormulario();
obj.setVisible(true);
}
}
Pueder ir al artículo principal:
Códigos Sencillos hechos en Java

Your article helped me a lot, is there any more related content? Thanks!
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?