Several ways to pop up a dialog box in swing _joptionpane.showmessagedialog

Source: Internet
Author: User

 several ways to pop up a dialog box in swing _joptionpane.showmessagedialogin swing, business-based considerations include a dialog box that restricts the user's behavior and prompts the user for action.

The Joptionpane class is available in swing to implement the functionality of the MessageBox like the Windows platform, as well as in Java, using individual static methods in the Joptionpane class

To generate a variety of standard dialog boxes, to display information, ask questions, warnings, user input parameters and other functions. These dialog boxes are modal dialogs.

Confirmdialog ---Confirm the dialog box, ask the question, and then be confirmed by the user (press "Yes" or "No" button)

INputdialog ---Prompt to enter text

Messagedialog ---display information

Optiondialog --Combine the other three types of dialog boxes.

These four dialogs can be displayed using Showxxxdialog (), such as Showconfirmdialog () display confirmation dialog, Showinputdialog () Display Input Text dialog box, Showmessagedialog () Display Information dialog box 、

Showoptiondialog () Displays the Selective dialog box.

The parameters they use are described below:

①parentcomponent: Indicates the parent window object of the dialog box, typically the current window. You can also null to use the default frame as the parent window, at which point the dialog box is set to the center of the screen.

②message: indicates descriptive text to display in the dialog box

③stringTitle: Header text string.

④component: components to display in a dialog box (such as buttons)

⑤icon: The icon to display in the dialog box

⑥messagetype: can generally be the following values Error_message, Information_message, Warning_message, Question_message, PLAIN_ MESSAGE,

⑦optiontype: It determines the button options to be displayed at the bottom of the dialog box. Generally can be default_option, yes_no_option, Yes_no_cancel_option, Ok_cancel_option.

Usage examples: (1) display Messagedialog joptionpane.showmessagedialog (null, "Descriptive text displayed in dialog box", "title bar text string", Joptionpane.error_message) ;

(2) Show Confirmdialog joptionpane.showconfirmdialog (null, "Choose one", "Choose One", joptionpane.yes_no_option);

(3) Display Optiondialog: The dialog box can be set by the user himself to the number of buttons and return to the user click on the individual buttons (starting from 0 count) object[] options = {"OK", "Cancel", "Help"};

int Response=joptionpane.showoptiondialog (This, "This is an option dialog box, the user can choose their own number of buttons", "Options dialog box title", Joptionpane.yes_option,

Joptionpane.question_message, NULL, Options, options[0]);

if (response==0) {this.settitle ("You pressed the OK button");

else if (response==1) {this.settitle ("You pressed the first cancel button");

else if (response==2) {this.settitle ("You pressed the section help button");}

(4) Display inputdialog in order for the user to enter String inputvalue = joptionpane.showinputdialog ("Please input a value");

(5) Display inputdialog in order for the user to enter object[] PossibleValues = {"First", "Second", "third"}; User's selection item

Object SelectedValue = Joptionpane.showinputdialog (null, "Choose One", "Input", joptionpane.information_message, NULL, PossibleValues, Possiblevalues[0]);

Settitle ("You pressed" + (String) selectedvalue+ "project");

Several ways to pop up a dialog box in swing _joptionpane.showmessagedialog

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.