I have a Java swing application with a button that produces a popup window when a certain action is performed. I\'d like to align the center point of the popup window with
setLocationRelativeTo..this sets the top left pixel of the popup over the center pixel of the parent. ..
No it does not!

Each of the 3 dialogs popped by this simple example appears to be centered as far as I can see. I can only guess that the code is calling setLocationRelativeTo at the wrong time.
import javax.swing.*;
class CenterTheDialog {
CenterTheDialog() {
for (int ii=1; ii<4; ii++) {
JFrame f = new JFrame("Frame " + ii);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(400,300);
f.setLocationByPlatform(true);
f.setVisible(true);
JDialog d = new JDialog(f);
d.setSize(300,200);
d.setLocationRelativeTo(f);
d.setVisible(true);
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
new CenterTheDialog();
});
}
}