Java Reference
In-Depth Information
TRY IT OUT: Adding Toolbar Buttons for the File Menu
I assume that you have added the declaration for the toolBar object to the SketcherFrame class and the
statements to the constructor that add it to the GUI:
public SketcherFrame(String title) {
// Constructor code as before...
createToolbar();
toolBar.setRollover(true);
getContentPane().add(toolBar, BorderLayout.NORTH);
}
Directory "Sketcher 7 with File toolbar buttons"
The icons for toolbar buttons, or anything else in Sketcher, can be created and stored as constants in the
SketcherConstants class, and they are available to any part of the program. Amend the class definition
as follows:
package Constants;
import java.awt.Color;
import javax.swing.*;
public class SketcherConstants {
// Path for images
public final static String imagePath = "D:/Sketcher/Images/";
// Toolbar icons
public final static Icon NEW24 = new ImageIcon(imagePath +
"New24.gif");
public final static Icon OPEN24 = new ImageIcon(imagePath +
"Open24.gif");
public final static Icon SAVE24 = new ImageIcon(imagePath +
"Save24.gif");
public final static Icon SAVEAS24 = new ImageIcon(imagePath +
"SaveAs24.gif");
public final static Icon PRINT24 = new ImageIcon(imagePath +
"Print24.gif");
// Rest of the class as before...
}
Directory "Sketcher 7 with File toolbar buttons"
Search WWH ::




Custom Search