Some common methods of the Joptionpane class hint box

Source: Internet
Author: User

The Joptionpane class encapsulates a number of methods.

Very convenient, so simple to tidy up a bit.

1.1 Showmessagedialog

Displays a modal dialog box with an OK button.

Here are a few examples of using Showmessagedialog:

Java code
    1. Joptionpane.showmessagedialog (NULL, "friendly hints");

The effect is as follows:

Java code
    1. Joptionpane.showmessagedialog (JPanel, "hint message", "title", Joptionpane.warning_message);

The effect is as follows:

Java code
    1. Joptionpane.showmessagedialog (NULL, "prompt message.", "title", Joptionpane.error_message);

Java code
    1. Joptionpane.showmessagedialog (NULL, "prompt message.", "title", Joptionpane.plain_message);

1.2 Showoptiondialog

This function can change the text displayed on the button. You can also perform more personalized actions.

General message Box:

Java code
    1. int n = joptionpane.showconfirmdialog (null, "Are you happy?", "title", joptionpane.yes_no_option);//I=0/1

The effect is as follows:

Statement message box:

Java code
    1. object[] Options ={"Good!" "Go aside!" " };
    2. int m = Joptionpane.showoptiondialog (null, "Can I ask you out?") "," title ", Joptionpane.yes_no_option, Joptionpane.question_message, NULL, Options, options[0]);

The effect is as follows:

1.3 Showinoutdialog

The method returns an object type. This type of object is typically a string type that reflects the user's input.

Example of the form of a drop-down list:

Java code
    1. Object[] Obj2 ={"Football", "basketball", "Table tennis"};
    2. string s = (string) Joptionpane.showinputdialog (NULL, "Please choose your hobby: \ n", "hobby", Joptionpane.plain_message, New ImageIcon (" Icon.png "), Obj2," football ");

The effect is as follows:



Examples of text box forms:

Java code
    1. Joptionpane.showinputdialog (NULL, "Please enter your hobby: \ n", "title", Joptionpane.plain_message,icon,null, "Enter in this");

The effect is as follows:



The corresponding small icon can be referenced by:



For detailed explanations, refer to the Oracle website

Some common methods of the Joptionpane class hint box

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.