Java Reference
In-Depth Information
You add the icons for the Color menu in the same way. First, add the icon definitions to SketcherCon-
stants :
public final static Icon RED24 = new ImageIcon(imagePath + "Red24.gif");
public final static Icon GREEN24 = new ImageIcon(imagePath + "Green24.gif");
public final static Icon BLUE24 = new ImageIcon(imagePath + "Blue24.gif");
public final static Icon YELLOW24 = new ImageIcon(imagePath + "Yellow24.gif");
Directory "Sketcher 8 with toolbar buttons and menu icons"
All the GIF files are in the same directory. I created very simple 24 <Symbol>× </Symbol>24 icons for
the Elements and Color menus and these are in the code download. You might like to create some fancier
versions.
Now update the method that creates the actions for the Color menu:
private void createElementColorActions() {
// Code as before...
// Add toolbar icons
redAction.putValue(LARGE_ICON_KEY, RED24);
greenAction.putValue(LARGE_ICON_KEY, GREEN24);
blueAction.putValue(LARGE_ICON_KEY, BLUE24);
yellowAction.putValue(LARGE_ICON_KEY, YELLOW24);
}
Directory "Sketcher 8 with toolbar buttons and menu icons"
Creating the Toolbar Buttons
You create the new toolbar buttons in the createToolbar() method in SketcherFrame :
private void createToolbar() {
// Code for File menu buttons as before...
toolBar.addSeparator();
// Create Color menu buttons
for(ColorAction action:colorActions){
addToolbarButton(action); // Add the toolbar button
}
toolBar.addSeparator();
Search WWH ::




Custom Search