Java Reference
In-Depth Information
It would be nice to have as many GUI features in Sketcher as possible, so let's add icons for the menu items,
too, to complement the toolbar icons. This is very easy. All you need to do is add IconImage objects as val-
ues for the SMALL_ICON key in the Action objects that you use to create the menu items. You can implement
this by first adding definitions for the icons for menu items to SketcherConstants :
// Menu item icons
public final static Icon NEW16 = new ImageIcon(imagePath + "new16.gif");
public final static Icon OPEN16 = new ImageIcon(imagePath + "Open16.gif");
public final static Icon SAVE16 = new ImageIcon(imagePath + " Save16.gif");
public final static Icon SAVEAS16 = new ImageIcon(imagePath + "SaveAs16.gif");
public final static Icon PRINT16 = new ImageIcon(imagePath + "print16.gif");
public final static Icon LINE16 = new ImageIcon(imagePath + "Line16.gif");
public final static Icon RECTANGLE16 = new ImageIcon(imagePath +
"Rectangle16.gif");
public final static Icon CIRCLE16 = new ImageIcon(imagePath + "Circle16.gif");
public final static Icon CURVE16 = new ImageIcon(imagePath + "Curve16.gif");
public final static Icon RED16 = new ImageIcon(imagePath + "Red16.gif");
public final static Icon GREEN16 = new ImageIcon(imagePath + "Green16.gif");
public final static Icon BLUE16 = new ImageIcon(imagePath + "Blue16.gif");
public final static Icon YELLOW16 = new ImageIcon(imagePath + "Yellow16.gif");
Directory "Sketcher 8 with toolbar buttons and menu icons"
The icons are 16 ×16 pixels to go with the menu items. Now you can add code to createFileMenuAc-
tions() to use these:
private void createFileMenuActions() {
// Code to create action objects as before...
// Code to add large icons to the action objects as before...
// Add menu item actions
newAction.putValue(SMALL_ICON, NEW16);
openAction.putValue(SMALL_ICON, OPEN16);
saveAction.putValue(SMALL_ICON, SAVE16);
saveAsAction.putValue(SMALL_ICON,SAVEAS16);
printAction.putValue(SMALL_ICON, PRINT16);
}
Directory "Sketcher 8 with toolbar buttons and menu icons"
Adding icons for the Elements menu items is similar. Add the following statements to the end of the cre-
ateElementTypeActions() method:
Search WWH ::




Custom Search