You can use an images in the tool bar. You can also insert the buttons in the tool bar which are the JButton instances. This instances also use an images from the Feel Graphics Repository. The following is a sample of teh coding that creates the buttons and adds them to the tool bar.
Code:
protected void addButtons(JToolBar toolBar) {
JButton button = null;
button = makeNavigationButton("Previous", PREVIOUS,
"go to previous page",
"Previous");
toolBar.add(button);
button = makeNavigationButton("Next", NEXT,
"go to next page",
"Next");
toolBar.add(button);
}
protected JButton makeNavigationButton(String imageName,
String actionCommand,
String toolTipText,
String altText) {
String imgLocation = "images/"
+ imageName
+ ".gif";
URL imageURL = ToolBarDemo.class.getResource(imgLocation);
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(this);
if (imageURL != null) {
button.setIcon(new ImageIcon(imageURL, altText));
} else {
button.setText(altText);
System.err.println("Resource not found: " + imgLocation);
}
return button;
}
Bookmarks