
If you need to control the dialog window-closing behavior or if you do not want the dialog to be modal, then you should directly instantiate JOptionPane and add it to a JDialog instance. If your dialog should be an internal frame, then add Internal after show for example, showMessageDialog changes to showInternalMessageDialog. Icons used by JOptionPane Icon descriptionįor most simple modal dialogs, you create and show the dialog using one of JOptionPane's show XxxDialog methods. The following figure shows the icons used in the Java (and Windows) look and feel. Each look and feel has its own versions of the four standard icons. You can use a custom icon, no icon at all, or any one of four standard JOptionPane icons (question, information, warning, and error). JOptionPane's icon support lets you easily specify which icon the dialog displays.
#Dialog maker code
When you create a JOptionPane, look-and-feel-specific code adds components to the JOptionPane and determines the layout of those components. You can even specify that an option pane put itself into an internal frame ( JInternalFrame) instead of a JDialog.

Other features allow you to customize the components the dialog displays and specify where the dialog should appear onscreen. JOptionPane provides support for laying out standard dialogs, providing icons, specifying the dialog title and text, and customizing the button text. Using JOptionPane, you can quickly create and customize several different kinds of dialogs. The dialog will disappear from the screen until you deiconify the DialogDemo window.
#Dialog maker download
Java™ Web Start ( download JDK 7 or later). Click the Launch button to run the Dialog Demo using.

Here is a picture of an application that displays dialogs. The reason is that JOptionPane is simply a container that can automatically create a JDialog and add itself to the JDialog's content pane.
#Dialog maker how to
If you're going to use JDialog directly, then you should understand the material in Using Top-Level Containers and How to Make Frames, especially Responding to Window-Closing Events.Įven when you use JOptionPane to implement a dialog, you're still using a JDialog behind the scenes. These are the same features that JFrame has, and using JDialog directly is very similar to using JFrame. It adds a root pane container and support for a default close operation to the Dialog object. The JDialog class is a subclass of the AWT Starting with JDK 7, you can modify dialog window modality behavior using the new Modality API. To create a non-modal Dialog, you must use the JDialog class directly. JOptionPane creates JDialogs that are modal.
#Dialog maker windows
When a modal Dialog is visible, it blocks user input to all other windows in the program.

A swing JDialog class inherits this behavior from the AWT Dialog class.Ī Dialog can be modal. When the frame is deiconified, its dependent Dialogs return to the screen. When the frame is iconified, its dependent Dialogs also disappear from the screen. When that Frame is destroyed, so are its dependent Dialogs. The rest of this section covers the following topics:Įvery dialog is dependent on a Frame component.

JOptionPane.showMessageDialog(frame, "Eggs are not supposed to be green.")
