Search code examples
javaswingjdialog

Purpose of JDialog#setModal


What is the purpose of d.setModal(true);?

public DatePicker(JFrame parent) {
    dialog = new JDialog();
    dialog.setModal(true);

    String[] header = { "Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat" };

    JPanel panel = new JPanel(new GridLayout(7, 7));
    panel.setPreferredSize(new Dimension(430, 120));

    ...
}

I have tried to search here, on StackOverflow, but did not find any convincing answer.


Solution

  • It's a good idea to check the main documentation: setModal

    modal - specifies whether dialog blocks input to other windows when shown;

    Also note that

    This method is obsolete and is kept for backwards compatibility only. Use setModalityType() instead.

    Then check the Dialog.ModalityType to see what your options are.