Java JOptionPane

The JOptionPane class is used to provide standard dialog boxes such as message dialog box, confirm dialog box and input dialog box. These dialog boxes are used to display information or get input from the user. The JOptionPane class inherits JComponent class.

JOptionPane class declaration

Common Constructors of JOptionPane class

Constructor Description
JOptionPane() It is used to create a JOptionPane with a test message.
JOptionPane(Object message) It is used to create an instance of JOptionPane to display a message.
JOptionPane(Object message, int messageType It is used to create an instance of JOptionPane to display a message with specified message type and default options.

Common Methods of JOptionPane class

Methods Description
JDialog createDialog(String title) It is used to create and return a new parentless JDialog with the specified title.
static void showMessageDialog(Component parentComponent, Object message) It is used to create an information-message dialog titled "Message".
static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) It is used to create a message dialog with given title and messageType.
static int showConfirmDialog(Component parentComponent, Object message) It is used to create a dialog with the options Yes, No and Cancel; with the title, Select an Option.
static String showInputDialog(Component parentComponent, Object message) It is used to show a question-message dialog requesting input from the user parented to parentComponent.
void setInputValue(Object newValue) It is used to set the input value that was selected or input by the user.

Java JOptionPane Example: showMessageDialog()

Output:

Java Joptionpane 1

Java JOptionPane Example: showMessageDialog()

Output:

Java Joptionpane 2

Java JOptionPane Example: showInputDialog()

Output:

Java Joptionpane 3

Java JOptionPane Example: showConfirmDialog()

Output:

Java Joptionpane 4
Next TopicJScrollBar




Contact US

Email:[email protected]

Java JOptionPane
10/30