Page 704 - Introduction to Programming with Java: A Problem Solving Approach
P. 704
670 Chapter 16 GUI Programming Basics Method Details
In Figure 16.10, note the message dialog box’s title-bar message—it’s “Message.” Kinda boring, eh? To liven things up, add a third argument to the showMessageDialog call that specifies the dialog box’s title. Also in Figure 16.10, note the message dialog box’s icon—it’s an i inside a circle. That’s the default icon. To ex- plicitly specify an icon, add a fourth argument to the showMessageDialog call that specifies one of the named constants in Figure 16.11.
Figure 16.11 Icon options within a JOptionPane dialog box
Here’s how to call the four-parameter version of showMessageDialog:
JOptionPane.showMessageDialog(
<null-or-container >, <message>, <title>, <icon_constant>);
Here’s an example four-argument showMessageDialog call and the resulting dialog box:
JOptionPane.showMessageDialog(null, "A virus has been detected.", "Warning",
JOptionPane.WARNING_MESSAGE);
JOptionPane
Named Constants
(for Specifying a
Dialog Box's Icon) Icon When to Use
INFORMATION_MESSAGE
For a dialog box that provides informational text.
WARNING_ MESSAGE
For a dialog box that warns the user about a problem.
ERROR_MESSAGE
For a dialog box that warns the user about an error. Normally, an error is considered to be more serious than a warning.
Apa
QUESTION_MESSAGE
go PDF Enhancer
For a dialog box that asks the user a question. Normally, the question-mark icon is used with a confirm dialog box or an input dialog box. But it is legal to use it with a message dialog box as well.
PLAIN_MESSAGE
no icon
For a plain-looking dialog box. The dialog box contains a message, but no icon.