Search code examples
javaswingjframejdialog

Access a modeless JFrame while a modal JDialog is visible?


Is it possible to access a modeless JFrame while a modal JDialog is visible?

I have a JFrame which shows my log lines. When i display a modal JDialog, for example to login, the user can't click the JFrame.

The JFrame isn't a parent/owner of the JDialog.

The JFrame is the first JFrame being created.

Note that when i do something in the JDialog that causes a log line to be added to the log i can see it appear in the JFrame.

Is this how it supposed to work or is it possible to let the user click the JFrame while the modal JDialog is visible?


Solution

  • It seems that using ModalityType.DOCUMENT_MODAL is the answer.

    Give the JDialog ModalityType.DOCUMENT_MODAL (setModalityType) and make sure setModal is false. The JDialog should also have owner/parent Window.

    The JFrame that should always be accessible should have no relation to the JDialog, so don't use it as owner/parent for the JDialog.

    Now the JDialog blocks the owner/parent Window but the JFrame is still accessible while the modal JDialog is displayed.

    Thanks go out to @Hovercraft Full Of Eels for pointing me to ModalityType.