Java Reference
In-Depth Information
private void addToolbarButton(Action action) {
JButton button = new JButton(action);
// Create from
Action
button.setBorder(BorderFactory.createCompoundBorder(
// Add
button border
new EmptyBorder(2,5,5,2),
// Outside
border
BorderFactory.createRaisedBevelBorder())); // Inside border
button.setHideActionText(true);
// No label on
the button
toolBar.add(button);
// Add the
toolbar button
}
Directory "Sketcher 7 with File toolbar buttons"
You need to add the following import statements to the SketcherFrame class:
import javax.swing.border.*;
import static javax.swing.Action.*;
Directory "Sketcher 7 with File toolbar buttons"
The first makes the border class names available without qualifiers and the second imports member
names in the Action class that define keys.
If you recompile Sketcher and run it, the window should look like that shown in Figure 18-9 .
FIGURE 18-9
How It Works
Calling putValue() for an Action object stores the value you specify by the second argument with the
key you supply as the first argument. The new statements in the createFileMenuActions() method add
an Icon object from the SketcherConstants class as the value corresponding to the LARGE_ICON_KEY
 
 
Search WWH ::




Custom Search