Question: I want to disable clicking on the background panel or frame while showing a dialogue. And I want the dialogue to appear on top of this panel or frame constantly until it is closed.

![Enter image description here](https://i.stack.imgur.com/v0qfM.png)

How can I do this?

Answer: 
Make [Dialog](http://download.oracle.com/javase/6/docs/api/java/awt/Dialog.html)/[JDialog](http://download.oracle.com/javase/6/docs/api/javax/swing/JDialog.html) modal by calling `dialog.setModal(true);`. This will solve both issues of clicking background panel and remaining on top of panel.

---

It seems like this method is obsolete so better you should use `dialog.setModalityType(Dialog.ModalityType type)`
You can use `JOptionPane` for the message dialog.