I am having trouble to set the frame as a owner to the dialog. Normally when I extend JDialog
class for creating a dialog then I use super(frame)
t
A dialog's (or window's) owner can be set only in the constructor, so the only way to set it is by using a constructor which takes the owner as parameter, like:
class DialogWithoutExtend {
private JFrame frame;
public DialogWithoutExtend(JFrame frame) {
this.frame = frame;
}
public void cretaUI() {
JDialog dialog = new JDialog(frame);
dialog.setTitle("Dialog created without extending JDialog class.");
dialog.setSize(new Dimension(400, 100));
dialog.setLocationRelativeTo(frame);
dialog.setModal(true);
dialog.setVisible(true);
}
}