Java Reference
In-Depth Information
If you recompile Sketcher and run it, the window should look like that shown below.
How It Works
There's not much to say about this. The add() method for the toolBar object created a button
based on the openAction object that we passed as an argument. We store the reference returned in
button so that we can add a border to the button.
A feature that comes for free with a JToolBar object is that it is automatically dockable, and can float
as an independent window. You can drag the toolbar using the mouse by clicking the cursor in the gray
area to the left of the button, and it will turn into a free-floating window.
You can also drag the toolbar to any of the four sides of the content pane to dock it again. You must
drag with the cursor in the gray area of the toolbar to dock it. Dragging with the cursor in the toolbar
title area just moves the window. It's not always convenient to have the toolbar floating or docked
against borders other than its normal position. You can inhibit the ability to drag the toolbar around by
calling the setFloatable() method for the JToolBar object, passing a boolean argument of false .
Let's do this for Sketcher, so add the following statement to the SketchFrame constructor before the
statement that adds the toolbar to the content pane:
toolBar.setFloatable(false); // Inhibit toolbar floating
getContentPane().add(toolBar, BorderLayout.NORTH);
}
Search WWH ::




Custom Search