Pop-up dialog box in swing

Source: Internet
Author: User

Today, I answered no questions about the pop-up box in swing. I also sorted out the pop-up box myself.

The pop-up dialog box in swing is implemented using joptionpane and displayed through showxxxdialog (). The pop-up dialog box is static.

There are four types of pop-up styles:

Confirmdialog: confirmation dialog box (similar to the "yes" and "no" buttons). You can also pass different parameters to change the displayed buttons and icons.

Inputdialog: text input dialog box

Messagedialog: displays messages.

Optiondialog: Custom dialog box (combination of the preceding three types)

The method parameters are as follows:

Parentcomponent: the parent window object of the dialog box. If it is null, the default frame is used as the parent window, And the dialog box is set in the middle of the screen.

Message: displays the message text. It can actually be any object. (I accidentally uploaded the jmenubar object on the form to display jmenubar)

Title: Title text

Component: components shown in (such as buttons)

Icon: The displayed icon (such as an exclamation point)

Messagetype: Generally, it can be error_message, information_message, warning_message, question_message, and plain_message.

Optiontype: it determines the button options to be displayed at the bottom of the dialog box. The options include default_option, yes_no_option, yes_no_cancel_option, and OK _cancel_option.

Instance used:
(1) display messagedialog
Joptionpane. showmessagedialog (null, "Information Content", "title", joptionpane. error_message );
(2) display confirmdialog
Joptionpane. showconfirmdialog (null, "select a", "title", joptionpane. yes_no_option );
(3) display optiondialog: In this dialog box, you can set the number of buttons and return the serial number of each button you click (counting starts from 0)
Object [] Options = {"OK", "cancel", "help "};
Int response = joptionpane. showoptiondialog (this, "Number of buttons that a user can select", "title", joptionpane. yes_option, joptionpane. question_message, null, options, options [0]);
If (response = 0 ){

This. settitle ("You have pressed the OK button ");
} Else if (response = 1 ){

This. settitle ("You have pressed the cancel button ");
} Else if (response = 2)
{

This. settitle ("You have pressed the Help button ");
}
(4) display inputdialog to allow users to enter
String inputvalue = joptionpane. showinputdialog ("Please input a value ");
(5) display inputdialog to allow users to selectively Input
Object [] possiblevalues = {"first", "second", "third"}; // select a project for the user
Object selectedvalue = joptionpane. showinputdialog (null, "select", "input", joptionpane. information_message, null, possiblevalues, possiblevalues [0]);
Settitle ("You have pressed" + (string) selectedvalue + "project ");

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.