Java Reference
In-Depth Information
public JOptionPane()
JOptionPane optionPane = new JOptionPane();
public JOptionPane(Object message)
JOptionPane optionPane = new JOptionPane("Printing complete");
public JOptionPane(Object message, int messageType)
JOptionPane optionPane = new JOptionPane("Printer out of paper",
JOptionPane.WARNING_MESSAGE);
public JOptionPane(Object message, int messageType, int optionType)
JOptionPane optionPane = new JOptionPane("Continue printing?",
JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
public JOptionPane(Object message, int messageType, int optionType,
Icon icon)
Icon printerIcon = new ImageIcon("printer.jpg");
JOptionPane optionPane = new JOptionPane("Continue printing?",
JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, printerIcon);
public JOptionPane(Object message, int messageType, int optionType, Icon icon,
Object options[ ])
Icon greenIcon = new DiamondIcon(Color.GREEN);
Icon redIcon = new DiamondIcon(Color.RED);
Object optionArray[] = new Object[] { greenIcon, redIcon} ;
JOptionPane optionPane = new JOptionPane("Continue printing?",
JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, printerIcon,
optionArray);
public JOptionPane(Object message, int messageType, int optionType, Icon icon,
Object options[], Object initialValue)
JOptionPane optionPane = new JOptionPane("Continue printing?",
JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, printerIcon,
optionArray, redIcon);
The JOptionPane Message Argument
The message argument is an Object , not a String . While you normally pass only a quoted string
as this argument, with an Object argument, you can basically display anything you want in the
message area. In the “Understanding the Message Property,” section later in this chapter, you'll
look at the more advanced uses of this argument. Briefly, though, there are four basic rules to
interpret the meaning of an Object -typed message argument. For elements within the Object ,
recursively follow these rules:
Search WWH ::




Custom Search