Java Reference
In-Depth Information
A true argument to the setFloatable() method allows the toolbar to float, so you can switch this
on and off in an application as you wish. You can also test whether a toolbar can float by calling the
isFloatable() method for the JToolBar object. This returns true if the toolbar is floatable and false
otherwise. If you recompile SketcherFrame and run Sketcher again you see that the gray bit at the left-
hand end of the toolbar is no longer there, and you cannot drag the toolbar around.
Adding More Toolbar Buttons with Icons
Now that you know how it works with the File menu, you can easily add toolbar buttons with icons corres-
ponding to the Elements and Color menus. The process is the same — first you add a large icon to each of
the Action objects and then you create the toolbar buttons from the Action objects.
Adding Large Icons for Element Type Selection Buttons
First add definitions for the icons as constants in the SketcherConstants class:
public final static Icon LINE24 = new ImageIcon(imagePath + "Line24.gif");
public final static Icon RECTANGLE24 = new ImageIcon(imagePath +
"Rectangle24.gif");
public final static Icon CIRCLE24 = new ImageIcon(imagePath + "Circle24.gif");
public final static Icon CURVE24 = new ImageIcon(imagePath + "Curve24.gif");
Directory "Sketcher 8 with toolbar buttons and menu icons"
Now you can add icons for the Elements menu action items like this:
private void createElementTypeActions() {
// Code as before...
// Add toolbar icons
lineAction.putValue(LARGE_ICON_KEY, LINE24);
rectangleAction.putValue(LARGE_ICON_KEY, RECTANGLE24);
circleAction.putValue(LARGE_ICON_KEY, CIRCLE24);
curveAction.putValue(LARGE_ICON_KEY, CURVE24);
}
Directory "Sketcher 8 with toolbar buttons and menu icons"
Adding Large Icons for Color Selection Buttons
Search WWH ::




Custom Search