JOptionPane Class

Package: javax.swing

JOptionPane has a number of static methods that display generic dialog boxes for simple user interaction. It is commonly used to display error or informational messages, to get the user’s confirmation to proceed with an operation, or to get a single input value.

Fields

Button Option Field

Description

static int YES_NO_OPTION

Yes or No.

static int YES_NO_CANCEL_OPTION

Yes, No, or Cancel.

static int OK_CANCEL_OPTION

OK or Cancel.

Message Type Field

Description

static int ERROR_MESSAGE

Error message.

static int INFORMATION_MESSAGE

Informational message.

static int WARNING_MESSAGE

Warning message.

static int QUESTION_MESSAGE

Question message.

static int PLAIN_MESSAGE

A plain message with no icon.

Return Value Field

Description

static int YES_OPTION

The user clicked Yes.

static int NO_OPTION

The user clicked No.

static int OK_OPTION

The user clicked OK.

static int CANCEL_OPTION

The user clicked Cancel.

static int CLOSE_OPTION

The user closed the dialog box.

Methods

Method

Description

static int showConfirm Dialog(Component parent, Object message)

Displays the indicated message and offers the user three choices: Yes, No, and Cancel. The user’s choice is indicated by the return value. The dialog box’s title defaults to Select an Option.

static int showConfirm Dialog(Component parent, Object message, String title)

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.