How to position a modal dialog box at the center of the screen?
Hi,
The modal dialog box is always getting displayed at the top-left hand corner of the screen. I have tried using setLocationRelativeTo(null), but it only serves to position the originating point of the dialog box at the center point of the launching window.
Here is the code for my dialog box class:
Code:
class MyDialog extends JDialog {
public MyDialog(Frame launchingWindow, BufferedImage image) {
super(launchingWindow, "Enlarged view of the selected image",
true); //launch this as a modal dialog.
JLabel imageDisplayer = new JLabel(new ImageIcon(image));
this.add(imageDisplayer, BorderLayout.CENTER);
this.pack();
}
}