In Visual Basic, a toolbar is generally designed to contain a series of buttons.
The ToolBar is a Microsoft Common Control. It is most often used in conjuction with another Common Control; the ImageList. Control.
The ImageList Contains a list of bitmap images. On the General settings for the Toolbar control an ImageList is specified. For each button on the toolbar, the image is specified by a number that is the index in the ImageList for the corresponding image.
Other properties specfied are captions and toolbar tips.
Java provides a similar toolbar with the identical concept that the toolbar contains common buttons. Actually, a Java toolbar is a Container and can contain any types of Java components.
JButtons can contain icons, captions and have tooltip text.
The code to implement this for a single button is:
// Declare a button and an ImageIcon JButton Toolbar1i2; ImageIcon ImageList1i2 = new ImageIcon("ImageList1i2.jpg"); . . . // Add the button to the toolbar with the Caption of 'Heart' and the proper icon Toolbar1i2 = (JButton) Toolbar1.add( new JButton("Heart",ImageList1i2)); Toolbar1i2.setToolTipText("You gotta have heart"); Toolbar1i2.setHorizontalTextPosition(SwingConstants.CENTER); Toolbar1i2.setVerticalTextPosition(SwingConstants.BOTTOM); Toolbar1i2 = (JButton) Toolbar1.add( new JButton("Heart",ImageList1i2)); Toolbar1i2.setToolTipText("You gotta have heart"); Toolbar1i2.setHorizontalTextPosition(SwingConstants.CENTER); Toolbar1i2.setVerticalTextPosition(SwingConstants.BOTTOM);The Text position commands place the caption at the bottom and center of the button.
That does it. It should be noted that an action event is associated with the button on the toolbar in the identical manner to any other button
Java does add the feature of making toolbars moveable. By using a borderlayout, the toolbar can be moved to the left, right, or bottom of the frame - not just the top. It can also be lifted out of the frame.
View or download the code and ask questions about it in the Forum
toolbarTest.frm The VB Form
toolbarTest.frx The VB Form binary file - Shift, Click to save
toolbarTest.java The Java code
Necessary images for icons