Java Reference
In-Depth Information
public JToggleButton(Icon icon, boolean selected)
JToggleButton aToggleButton = new JToggleButton(new DiamondIcon(Color.PINK), true);
public JToggleButton(String text)
JToggleButton aToggleButton = new JToggleButton("Sicilian");
public JToggleButton(String text, boolean selected)
JToggleButton aToggleButton = new JToggleButton("Thin Crust", true);
public JToggleButton(String text, Icon icon)
JToggleButton aToggleButton = new JToggleButton("Thick Crust",
new DiamondIcon(Color.PINK));
public JToggleButton(String text, Icon icon, boolean selected)
JToggleButton aToggleButton = new JToggleButton("Stuffed Crust",
new DiamondIcon(Color.PINK), true);
public JToggleButton(Action action)
Action action = ...;
JToggleButton aToggleButton = new JToggleButton(action);
Each allows you to customize one or more of the label, icon, or initial selection state.
Unless specified otherwise, the label is empty with no text or icon, and the button initially is
not selected.
Note Surprisingly, Swing lacks a constructor that accepts only an initial state of a boolean setting.
Lacking this constructor, you need to create a JToggleButton with the no-argument constructor variety,
and then call setSelected(boolean newValue) directly or work with an Action .
JToggleButton Properties
After creating a JToggleButton , you can modify each of its many properties. Although there are
about 100 inherited properties, Table 5-1 shows only the two introduced with JToggleButton .
The remaining properties come from AbstractButton , JComponent , Container , and Component .
Table 5-1. JToggleButton Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
UIClassID
String
Read-only
You can change one or more of the text , icon , or selected properties set in the constructor,
as well as any of the other AbstractButton properties described in Chapter 4. You configure
 
Search WWH ::




Custom Search