Java Reference
In-Depth Information
The
orientation
property can be set to only one of the
HORIZONTAL
or
VERTICAL
constants
of
JToolBar
. If another nonequivalent value is used, an
IllegalArgumentException
is thrown.
Changing the orientation changes the layout manager of the toolbar. If you directly change the
layout manager with
setLayout()
, changing the orientation will undo your layout change.
Consequently, it's best not to manually change the layout manager of a
JToolBar
.
As previously mentioned, a toolbar is floatable by default. This means that a user can drag
the toolbar from where you place it and move it elsewhere. To drag a toolbar, the user selects
an empty part of it. The toolbar can than be left outside the original program window, floating
above the main window in its own window, or dropped onto another area of the original
program window. If the layout manager of the original window is
BorderLayout
, the droppable
areas are the edges of the layout manager without any components. (You can't drop the toolbar
in the center of the window.) Otherwise, the toolbar would be dropped into the last spot of the
container. Figure 6-10 shows the different phases of the dragging and docking process.
Dragging Hot Spot
Floating
Docked in a Different Area
Undocked Floating Toolbar
Figure 6-10.
JToolBar phases