How to create a JToolbar

We use the JFrame created before to provide it with a new toolbar. First we have to select the frame in the components tree. Before adding the toolbar we have to set the Layout property of the frame to BorderLayout. This is because the toolbar needs to place itself on the North, West, South or East of a panel. When changing the layout of the frame to BorderLayout we also have to change the Constraint property of the JDesktopPane in our example to Center because the GUI builder has to know where to place the JDesktopPane within the frame.

After making sure we have again selected the frame in our tree, we press new JToolBar from the toolbar, set the Constraint property here to North and save the Component as known. Then we select this Component in the tree and repeat three times to select new JButton from the toolbar and set the following properties:

Name CP ( classpath ) Icon Tooltip
btnNew checked /toolbarButtonGraphics/general/New24.gif New File
btnOpen checked /toolbarButtonGraphics/general/Open24.gif Open File
btnClose checked /toolbarButtonGraphics/general/Export24.gif Close File

Save all your properties data, select the frame in the tree and check it. As you can see you have a ready-to-use toolbar.