Java >
Guidelines Home Page >  Java Look and Feel Design Guidelines
Part III: The Components of the Java Foundation Classes
8: Dialog Boxes and Alert Boxes
Alert Boxes
  Previous Next Contents/Index/Search

Alert Boxes

An alert box, which conveys a message or warning to users, provides an easy way for you to create a secondary window. The JFC provides four types of alert boxes: Info, Warning, Error, and Question. Each alert box is provided with a symbol that indicates its type. You provide the title, the message, and the command buttons and their labels.

The layout of an alert box is provided in the JFC, so you don't have to worry about the spacing and alignment of the message, symbol, and command buttons. If you provide additional components, such as a text field, follow the guidelines in Between-Component Spacing Guidelines. You can make an alert box modal or modeless.

Figure 121   Standard Components in an Alert Box


Alert Box Components

  In an alert box, begin your message with a brief heading in boldface. Start the body of the message on a separate line.

  If appropriate, provide a Help button in an alert box that opens an additional window with more information. Do not close the alert box when users click the Help button.

  In the message for an alert box, the <B>...</B> tags can be used to render a heading in boldface. The <BR> tag can be used to create a line break between the heading and the message body.

  An alert box is created using the JOptionPane component.

For guidance on window title text for alert boxes, see Title Text in Secondary Windows.

Info Alert Boxes

An Info alert box presents general information to users. The symbol in the Info alert box is a blue circle with the letter i. The following dialog box, which contains a schedule reminder, provides information about a meeting.

Figure 122   Info Alert Box


Info Alert Box

  Provide a Close button to dismiss an Info alert box. Provide additional command buttons, such as a Help button, if needed.

Warning Alert Boxes

A Warning alert box warns users about the possible consequences of an action and asks users for a response. The symbol in the Warning alert box is a yellow triangle with an exclamation point. The alert box in Figure 123 warns users that a file save operation will replace an existing file.

 Click here to view the corresponding code for Figure 123 (also available on the book's companion CD-ROM).

Figure 123   Warning Alert Box


Warning Alert Box

  Keep the message in a Warning alert box brief, and use terms that are familiar to users.

  Include at least two buttons in a Warning alert box: one button to perform the action and the other to cancel the action. Provide the command buttons with labels that describe the action they perform.

  Do not make a command button whose action might cause loss of data the default button. Users might press the Enter (or Return) key without reading the message. If the action that could result in data loss is the most common action, do not provide a default button. (For an example of a dialog box with this situation, see Figure 115.)

Error Alert Boxes

An Error alert box reports system and application errors to users. The symbol in the Error alert box is a red octagon with a rectangle. The following Error alert box reports that a printer is out of paper and provides users with three options. Clicking the Continue button resumes printing and dismisses the alert box. Clicking the Cancel button terminates the print job and dismisses the alert box. Clicking the Help button opens a secondary window that gives background information about the error.

Figure 124   Error Alert Box


Error Alert Box

  Include an error number in the title bar of an Error alert box. The error number is helpful for users in obtaining technical assistance, especially if the error message is localized in a language not spoken by the technical support personnel.

  In the message of an Error alert box, explain what happened, the cause of the problem, and what the user can do about it. Keep the message brief and use terms that are familiar to users.

  If appropriate, provide a Help button in an Error alert box to open a separate window that gives background information about the error. Do not close the alert box when users click the Help button.

  If possible, provide buttons or other controls to resolve the error noted in the Error alert box. Label the buttons according to the action they perform. If users cannot resolve the error from the alert box, provide a Close button.

Question Alert Boxes

A Question alert box requests information from users. You can add components to this alert box (for example, a text field, list box, or combo box) in which users can type a value or make a selection. The layout of the standard components (the symbol, message, and command buttons) is provided by the JFC. If you add components, follow the guidelines in Between-Component Spacing Guidelines. The symbol in the Question alert box is a green rectangle with a question mark.

The following Question alert box includes a label and text field in addition to the standard components.

Figure 125   Question Alert Box


Question Alert Box

  When you add components to a Question alert box, align them with the leading edge of the message. For languages that read from left to right, the leading edge is the left edge.

Java Look and Feel Design Guidelines, second edition.
Copyright 1994-2004 Sun Microsystems, Inc. All Rights Reserved.
Previous Next Contents/Index/Search
Left Curve
Java SDKs and Tools
Right Curve
Left Curve
Java Resources
Right Curve
Java 8 banner (182)