Different types of popup dialog boxes in Java

Source: Internet
Author: User

  JOptionPaneHelps to easily pop up a standard dialog box that asks the user for a value or notifies themAlthough many of the methodsJOptionPaneThe class may appear complex, but almost all of the use of this class is for the following static  One-way call :

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/07/BA/wKiom1nOQBiRwJ0SAAA3CwO7ADo237.png "title=" 002_ . png "alt=" Wkiom1noqbirwj0saaa3cwo7ado237.png "/>

showinternalxxx   style appears, this style uses the internal form to save the dialog box. It also defines a number of convenient methods that overload those basic methods and use different parameter lists.

all dialog boxes are modal. Each method blocks the caller until the user interaction is complete showXxxDialog .


displays an error dialog box that displays the message ' Alert ' :


    • JOptionPane.showMessageDialog(null, "alert", "alert", JOptionPane.ERROR_MESSAGE);


displays an internal Information dialog box with the message ' Information ' :


    • JOptionPane.showInternalMessageDialog(frame, "information","information", JOptionPane.INFORMATION_MESSAGE);


displays an information panel with options of "yes/no" with message ' Choose one ' :


    • JOptionPane.showConfirmDialog(null,"choose one", "choose one", JOptionPane.YES_NO_OPTION);


displays an internal Information dialog box with the options "Yes/no/cancel", message ' Please choose one ', and a title message :


    • JOptionPane.showInternalConfirmDialog(frame,"Please choose one", "Information",JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);


Displays a warning dialog box with options OK, cancel,title ' Warning ', and message ' Click OK to continue ':


    • Object[] options = { "OK", "CANCEL" };
      JOptionPane.showOptionDialog(null, "Click OK to continue", "Warning",

      Joptionpane.default_option, Joptionpane.warning_message,null, options, options[0]);


Displays a dialog box that asks the user to type a String:


    • String inputValue = JOptionPane.showInputDialog("Please input a value");


Displays a dialog box that asks the user to select a String:


    • Object[] possibleValues = { "First", "Second", "Third" };

    • Object selectedvalue = Joptionpane.showinputdialog (null,"Choose One", "Input"

Joptionpane.information_message, Null,possiblevalues, possiblevalues[0]);


Create and use Joptionpane directly


   //specific parameter meanings can be consulted in Java document  joptionpane pane = new joptionpane (arguments);      pane.set.xxxx (...);  // configure     jdialog dialog = pane.createdialog ( Parentcomponent, title);      dialog.show ();      object  selectedvalue = pane.getvalue ();      if (selectedValue ==  NULL)        return closed_option;     //if  there is not an array of option buttons:      if (options == null)  {       if (selectedValue  Instanceof integer)           return  ((Integer) SelectedValue). Intvalue ();        return closed_option;      }     //if there is an array of  option buttons:     for (Int counter = 0, maxcounter  = options.length;        counter < maxCounter;  counter++)  {        if (Options[counter].equals ( SelectedValue))         return counter;      }     return CLOSED_OPTION;


Reference: Online API documentation



This article is from the "Guardian" blog, please be sure to keep this source http://acevi.blog.51cto.com/13261784/1969841

Different types of popup dialog boxes in Java

Related Article

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.