Search This Blog

Showing posts with label modality. Show all posts
Showing posts with label modality. Show all posts

What Does Modal and Modeless (Non Modal) Mean in Java

In java, the dialogue boxes in JOptionPane class are very popular. Now when we use dialogue boxes, whether it is message dialogue box, input dialogue or any other,  we may sometimes need to make the parent container (often JFrame or JWindow) not focusable. In another words, we may have to prevent a (parent) component taking input from the user while one of its member component is active. (You may have noticed that when error message boxes are displayed, you cannot click its parent window on many software until you dismiss it by clicking 'OK' or 'close'). Such a property of a member or child component, is called modality. In java, you can use JDialog with or without modality. A JDialog can be either modal or modeless.
A Modal dialog box is a dialog box that blocks input to some other top-level windows in the application. The modal dialog box captures the window focus until it is closed, usually in response to a button press.
A Modeless dialog box is a dialog box that does not block input to any other top level window while it is shown.
See following java code example: