Java: What is the property of the JOptionPane object that prevents clicks underneath itself?

I created my own JOptionPane using JDialog, but I cannot reproduce the behavior of a typical JOptionPane that prevents the user from clicking anywhere except the JOptionPane window.

What JOptionPane property do I need to replicate with JDialog so that I can simulate this behavior? (I know that JOptionPanes are just specialized JDialogs, as you can see if you look at the source code for the JOptionPane class).

+4
source share
2 answers

This is nothing more than a modal JDialog, and it is the modality that gives it this property. As far as I know, you cannot copy this directly without creating and using modal JDialog. You must be sure that JDialog is configured to access the correct parent window (often a JFrame) and that its ModalityType is set correctly.

+4
source

The Swing API to set the modality JDialog is one of the constructors with Dialog.ModalityType as an argument.

To set modality after creation: java.awt.setModalityType ()

To get modality use java.awt.Dialog.getModalityType ()

The old way is to use booleans (other constructors).

Sometimes we want to exclude some operating systems from modality using java.awt.setModalExclusionType () (rarely used)

+5
source

Source: https://habr.com/ru/post/1484484/


All Articles