Java >
Guidelines Home Page >  Java Look and Feel Design Guidelines
>
Part III: The Components of the Java Foundation Classes
> 10: Basic Controls >
Toggle Buttons
  Previous Next Contents/Index/Search


Toggle Buttons

A toggle button is a button that represents a setting with two states--on and off. Toggle buttons look similar to command buttons and display a graphic or text (or both) to identify the button. The graphic or button text should remain the same whether the button is in the on or off state. The state is indicated by highlighting the background of the buttons.

Users can click toggle buttons to turn a setting on or off--for instance, to switch between italic and plain style in selected text.

You can use toggle buttons to represent an independent choice, like checkboxes (click here), or an exclusive choice within a set, like radio buttons (click here).

  Toggle buttons can be placed in a button group to get radio button behavior.

Independent Choice

An independent toggle button behaves like a checkbox. Whether it appears alone or with other buttons, its setting is independent of other controls. An example of an independent toggle button is a Bold button on a toolbar, as shown in the following illustration.

Figure 154   Independent Toggle Buttons in a Toolbar

 

Independent Toggle Buttons

When users click the Bold button, it is highlighted to indicate that the bold style has been applied to the selection or that text to be entered will be bold. If the button is clicked again, it reverts to the normal button appearance and the bold style is removed from the selection.

  Although checkboxes and independent toggle buttons have the same function, as a general rule, use checkboxes in dialog boxes and menus and use toggle buttons with a graphic in toolbars.

  Use toggle buttons (instead of checkboxes) in dialog boxes if you need consistency with a toolbar.

For recommendations on the spacing of toggle buttons, see Toggle Button Spacing.

Exclusive Choice

A toggle button can work as part of a group to represent an exclusive choice within the set. A common example is a set of toolbar toggle buttons representing left, centered, and right text alignment, as shown in the following figure.

Figure 155   Exclusive Toggle Buttons

 

Exclusive Toggle Buttons

If users click the button representing left alignment, the button is highlighted to indicate that text is aligned flush with the left border of the document. If users then click the button representing centered alignment, the appearance of the Align Left button reverts to the normal button appearance and the Center button is highlighted to indicate centered alignment of the selected text.

You can use grouped toggle buttons with labels equally well in toolbars or dialog boxes. In the example in Figure 156, the label identifies the abbreviations in the button text within a dialog box.

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

Figure 156   Grouped Toggle Buttons With a Label

 

Toggle Buttons With Label

For spacing guidelines for exclusive toggle buttons, see Checkbox and Radio Button Layout and Spacing.


Java Look and Feel Design Guidelines, second edition.
Copyright 2001. 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
JavaOne Banner Java 8 banner (182)