Java Reference
In-Depth Information
Now the icons are generally available. The imagePath object defines the path to where the .gif files for
the icons are stored. If you are storing them in a different location, just change the definition of im-
agePath .
The next step is to amend the createFileMenuActions() method in SketcherFrame to add large icons
to the action objects:
private void createFileMenuActions() {
// Code to create action objects as before...
// Add toolbar icons
newAction.putValue(LARGE_ICON_KEY, NEW24);
openAction.putValue(LARGE_ICON_KEY, OPEN24);
saveAction.putValue(LARGE_ICON_KEY, SAVE24);
saveAsAction.putValue(LARGE_ICON_KEY, SAVEAS24);
printAction.putValue(LARGE_ICON_KEY, PRINT24);
}
Directory "Sketcher 7 with File toolbar buttons"
Only five of the menu items have corresponding toolbar buttons so you only add large icons to the Ac-
tion objects you use to create these.
Next you need add another method in the SketcherFrame class that adds buttons to the toolbar:
private void createToolbar() {
for(FileAction action: fileActions){
if(action != exitAction && action != closeAction)
addToolbarButton(action);
// Add the
toolbar button
}
}
Directory "Sketcher 7 with File toolbar buttons"
This adds a toolbar button using a helper method, addToolbarButton() . You add a toolbar button for
each action object you used to create the File menu items except for those for the Close and Exit menu
items.
You can now add the helper method to the SketcherFrame class that creates a button and adds it to the
toolbar:
Search WWH ::




Custom Search