Search code examples
javaswingmodal-dialogjoptionpanejdialog

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


I have created my own JOptionPane using a JDialog, but I can't seem to replicate the behavior of a typical JOptionPane that disallows the user from clicking anywhere but the JOptionPane window.

What property of JOptionPane do I need to replicate with a JDialog so that I can mimic this behavior? (I am aware that JOptionPanes are simply specialized JDialogs, as you can see if look at the JOptionPane class source code).


Solution

  • It is nothing more than a modal JDialog and it's the modality that gives it this property. You cannot replicate this directly without creating and using a modal JDialog as far as I know. You must be sure that the JDialog is set to refer to the correct parent window (often a JFrame) and that its ModalityType is set correctly.