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

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 be 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.

Table of Contents

 About This Java Swing Tutorial Book

 Introduction of Java Swing Package

 Graphics Environment of the Local System

 JFrame - Main Frame Class

 JLabel - Swing Label Class

 JButton - Swing Button Class

 JRadioButton - Swing Radio Button Class

 JTextField - Swing Text Field Class

 Menu Bar, Menus, Menu Items and Listeners

 Creating Internal Frames inside the Main Frame

 Layout of Components in a Container

 LookAndFeel and UIManager

Option Dialog Boxes

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

 JEditorPane - The Editor Pane Class

 References

 Printable Copy - PDF Version

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