What you are referring to is modality1, for which case a modal JDialog
is more appropriate than a JFrame
. See more at How to Use Dialogs
Also, if this is a simple message popup, a simple JOptionPane
would be more suitable. You can also see how to use JOptionPanes
in the link above.
Here's a simple JOPtionPane
example. Though I don't use a frame in the example, if you do have a frame, the JOptionPane
will block any user interaction.
import javax.swing.JOptionPane;
public class SimpleErrorMessage {
public static void main(String[] args) {
JOptionPane.showMessageDialog(
null, "Error!", "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
- See
JOptionPane
API for more dialog options.
1. A dialog box can be either modeless or modal. A modal dialog box is one that blocks input to some other top-level windows in the application, except for any windows created with the dialog box as their owner. The modal dialog box captures the window focus until it is closed, usually in response to a button press