Java Swing Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.00

javax.swing.JOptionPane - Creating and Displaying Option Dialog Boxes

This section describes some static methods in the JOptionPane class that can be used to create and display different types of option dialog boxes.

javax.swing.JOptionPane - A Swing class that allows to create and display option dialog boxes. Interesting methods of JOptionPane include:

  • showMessageDialog() - Method to create and display a message dialog box to present regular, warning or error messages.
  • showConfirmDialog() - Method to create and display a confirmation dialog box with yes, no and cancel buttons.
  • showInputDialog() - Method to create and display an input dialog box to prompt for some input.
  • showOptionDialog() - Method to create and display a generic dialog box to present message, take a confirmation, or take some input.
  • showInternal*Dialog() - Methods to create and display internal dialog boxes, displayed inside the main frame.

All dialog boxes created with the JOptionPane class are modal, disabling all other user interface components on other frames. Each call of show*Dialog() method blocks the execution until the dialog box is closed.

All dialog boxes must created with parent frame.

The message type of an option dialog box controls the icon used on the left side of the message text.

The option type of an option dialog box controls what option buttons to be displayed.

The option buttons can be customized with your own option strings.

Last update: 2009.

Sections in This Chapter

javax.swing.JOptionPane - Creating and Displaying Option Dialog Boxes

showMessageDialog() - Displaying Message Dialog Boxes

showConfirmDialog() - Displaying Confirmation Dialog Boxes

Receiving Inputs from Confirmation Dialog Boxes

showInputDialog() - Displaying Input Dialog Boxes

showOptionDialog() - Displaying Option Dialog Boxes

showInternal*Dialog() - Displaying Internal Dialog Boxes

createDialog() - Creating Dialog Boxes Directly

Dr. Herong Yang, updated in 2009
javax.swing.JOptionPane - Creating and Displaying Option Dialog Boxes