Common Methods of joptionpane prompt box

Source: Internet
Author: User
Common Methods of joptionpane prompt box xmloracleswing

Recently I encountered a message prompt box in a swing program. The joptionpane class encapsulates many methods.

It was very convenient, So I simply sorted it out.

1.1 showmessagedialog

A modal dialog box with the OK button is displayed.

The following are several examples of using showmessagedialog:

Java code
  1. Joptionpane. showmessagedialog (null, "tip ");

The effect is as follows:

Java code
  1. Joptionpane. showmessagedialog (jpanel, "message", "title", joptionpane. warning_message );

The effect is as follows:

Java code
  1. Joptionpane. showmessagedialog (null, "message.", "title", joptionpane. error_message );


Java code
  1. Joptionpane. showmessagedialog (null, "message.", "title", joptionpane. plain_message );


 

1.2 showoptiondialog

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

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:

Personalized message box:

Java code
  1. Object [] Options = {"OK! "," Go to the other side! "};
  2. Int M = joptionpane. showoptiondialog (null, "can I ask you? "," Title ", joptionpane. yes_no_option, joptionpane. question_message, null, options, options [0]);

The effect is as follows:

1.3Showinoutdialog

This method returns an object type. This object type is generally a string type, reflecting the user input.

Example of a drop-down list:

Java code
  1. Object [] obj2 = {"football", "basketball", "Table Tennis "};
  2. String S = (string) joptionpane. showinputdialog (null, "Please select your hobbies: \ n", "hobbies", joptionpane. plain_message, new imageicon ("icon.png"), obj2, "soccer ");

The effect is as follows:

Example of text box format:

Java code
  1. Joptionpane. showinputdialog (null, "Enter your hobbies: \ n", "title", joptionpane. plain_message, icon, null, "Enter here ");

The effect is as follows:

For the corresponding small icons, refer:

For more information, see the Oracle official website.

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.