java left logo
java middle logo
java right logo
 

Home arrow Java SE Tips arrow javax.swing arrow How to create an Option Dialog Box
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4093
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to create an Option Dialog Box E-mail
User Rating: / 69
PoorBest 

The most complex of the dialog boxes is the option dialog box, which combines the features of all the other dialogs (Confirm Dialog Box, Input Dialog Box and Message Dialog Box). It can be created with the showOptionDialog(Component, Object, String, int, int, Icon, Object[], Object) method of JOptionPane class.

The arguments to this method are as follows:

  • The parent component of the dialog
  • The text, icon or component to display
  • A string to display in the title bar
  • The type of box, using the class constants YES_NO_OPTION or YES_NO_CANCEL_OPTION, or the literal 0 if other buttons will be used instead.
  • The icon to display, using the class constants ERROR_MESSAGE, INFORMATION_MESSAGE, PLAIN_MESSAGE, QUESTION_MESSAGE or WARNING_MESSAGE, or the literal 0 if none of these will be used.
  • An Icon object to display instead of one of the icons in the preceding argument
  • An array of objects holding the components or other objects that represent the choices in the dialog box. (if YES_NO_OPTION and YES_NO_CANCEL_OPTION are not being used.)
  • The object representing the default selection. (if YES_NO_OPTION and YES_NO_CANCEL_OPTION are not being selected.)

The following example creates an option dialog box that uses an array of JButton objects for the options in the box and color[3] as the default selection:

JButton[] color = new JButton[4];
color[0new JButton("Blue");
color[1new JButton("Red");
color[2new JButton("Green");
color[3new JButton("Yellow");

int response = JOptionPane.showOptionDialog(null,
"Which color do you like?",
"Color",
0,
JOptionPane.INFORMATION_MESSAGE,
null,
color,
color[3]);

 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.