Use of joptionpane

Source: Internet
Author: User

Joptionpane is a convenient form of dialog box, which is easier to use than jdialog, but has fixed types, and jdialog can be customized.

First, we will introduce four static methods of joptionpane that can be called directly by class name.

1. showmessagedialog Display message dialog box

@ This function has five parameters:

Component parent refers to the carrier of the message dialog box, which is generally a window.

Object message refers to the prompt information to be displayed.

String title form name

Int messagetype message display format:

Error_message

Information_message

Warning_message

Question_message

Plain_message

The message display formats and icons are different, and the rest are the same.

Icon of the message. Someone may ask what is the difference between this and the previous one. The difference is that it can be customized, And the last messagetype has only a few forms.

@ Although there are so many parameters, there are three manifestations of method overloading:

Showmessagedialog (parent, message) the default message display type is information_message.

Showmessagedialog (parent, message, title, messagetype)

Showmessagedialog (parent, message, title, messagetype, icon)

@ This function has no return value

Note:

A static function named showinternalmessagedialog has the same parameters and representations as showmessagedialog. The only difference is that the internal dialog box is completely displayed in the framework.

2. The showconfirmdialog dialog box is displayed.

@ The parameter of this function is the same as that of showmessagedialog, but an additional parameter is:

Int optiontype. This parameter indicates the selection type of the dialog box.

Default_option

Yes_no_option

Yes_no_cancel_option

OK _cancel_option

The differences between buttons displayed in different interpretations

@ Same as showconfirmdialog, there are also three reload forms

Showconfirmdialog (parent, message, title, optiontype, messagetype, icon)

Showconfirmdialog (parent, message, title, optiontype, messagetype)

Showconfirmdialog (parent, message) DefaultOfOptiontype is yes_no_cancel_option

Note: showinternalconfirmdialog is also available.

@ The return value of this function is an integer.

3. The showinputdialog dialog box is displayed.

@ The four parameters of this function are the same as those of showmessagedialog, but there are two more parameters:

Object [] value this is a set of values selected by the user. It is an array of objects, such as new string [] {"we", "you", "our"}. If it is null, indicates that the user can enter any input, and jtextfield is used for implementation.

Object default: This is the default value at the beginning of the program.

@ Reload has a form

Showinputdialog (parent, message, title, messagetype, icon, values, default)

Example: joptionpane. showinputdialog (null, "woahsi", "jljjk", joptionpane. error_message, null, new string [] {"DF", "dfdf", "dfdfdf"}, "dfdf ");

Showinputdialog (parent, message, title, messagetype)

Showinputdialog (parent, message)

 

The default messagetype is question_message.

Showinputdialog (Message)

There is no parent framework than above

Showinputdialog (parent, message, default)

 

Default values are added.

Showinputdialog (message, default)

Compared with the above, there is no parent framework

@ Return value is a string

Note:

Showinternalinputdialog is also available, but there are only three reload forms.

Showinternalinputdialog (parent, message, title, messagetype, icon, values, default)

Showinternalinputdialog (parent, message, title, messagetype)

Showinternalinputdialog (parent, message)

4. showoptiondialog show selection dialog box

This function is a combination of messagetype, optiondialog, and inputdialog, but is displayed by a button.

The format is:

Showoptiondialog (parent, message, title, optiontype, messagetype, icon, values, default)

Joptionpane. showoptiondialog (null, "woahsi", "nihao", joptionpane. yes_no_option, joptionpane. error_message, null, new string [] {"D", "F"}, "F ");

The default value is the 'F' key.

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.