Para centrar un JDialog en su JFrame Padre tenemos que hacer lo siguiente:
1.Centramos en la pantalla el JFrame Padre (setLocationRelativeTo(null)).
2.Centramos el JDialog con respecto al JFrame Padre (setLocationRelativeTo(frame)).
El código es el siguiente:
Código PHP:
import javax.swing.JFrame;
public class Prueba{
public static void main(String[] args){
JFrame frame = new JFrame("Prueba JFrame");
frame.setSize(500, 500);
frame.setLocationRelativeTo(null);
final JButton boton = new JButton("Abrir Dialogo");
boton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog dialogo = new JDialog(frame);
dialogo.setSize(100, 100);
dialogo.setLocationRelativeTo(frame);
dialogo.setVisible(true);
}
});
frame.add(boton);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Si te sirvio de algo comenta