JToolBar provides a component that is useful for
displaying commonly used Actions or controls.
For examples and information on using tool bars see
How to Use Tool Bars,
a section in The Java Tutorial.
With most look and feels,
the user can drag out a tool bar into a separate window
(unless the floatable property is set to false).
For drag-out to work correctly, it is recommended that you add
JToolBar instances to one of the four "sides" of a
container whose layout manager is a BorderLayout,
and do not add children to any of the other four "sides".
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
Action
| Modifier and Type | Class and Description |
|---|---|
| protected class | JToolBar.
This class implements accessibility support for the
|
| private class | |
| public static class | JToolBar.
A toolbar-specific separator. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private Insets | |
| private int | |
| private boolean | |
| private static final String |
| Access | Constructor and Description |
|---|---|
| public | |
| public | JToolBar(int
the orientation desired orientation)Creates a new tool bar with the specified |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public JButton | |
| protected void | addImpl(Component
the component to be enhanced comp, Object the constraints to be enforced on the component constraints, int the index of the component index)Overrides java. If a |
| public void | |
| public void | addSeparator(Dimension
the size)Dimension of the separatorAppends a separator of a specified size to the end of the tool bar. |
| private void | |
| protected PropertyChangeListener | Returns: nulla b)JButtonReturns a properly configured |
| protected JButton | Returns: the newly created buttonthe a)Action for the button to be addedFactory method which creates the |
| public AccessibleContext | Returns: an AccessibleJToolBar that serves as the AccessibleContext of this JToolBarOverrides java. Implements javax. Gets the AccessibleContext associated with this JToolBar. |
| public Component | Returns: theComponent at that position,
or null for an invalid indexthe component's position, where 0 is first i)Returns the component at the specified index. |
| public int | Returns: an integer indicating the component's position, where 0 is firstthe c)Component to findReturns the index of the specified component. |
| public Insets | Returns: anInsets object containing the margin valuesReturns the margin between the tool bar's border and its buttons. |
| public int | Returns: an integer representing the current orientation -- eitherHORIZONTAL or VERTICALReturns the current orientation of the tool bar. |
| public ToolBarUI | Returns: the tool bar's current UI.Overrides javax. Returns the tool bar's current UI. |
| public String | Returns: the string "ToolBarUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if rollover toolbar buttons are to be drawn; otherwise falseReturns the rollover state. |
| protected void | paintBorder(Graphics
the g)Graphics context in which the painting
is doneOverrides javax. Paints the tool bar's border if the |
| protected String | Returns: a string representation of thisJToolBar.Overrides javax. Returns a string representation of this |
| public void | setBorderPainted(boolean
if true, the border is painted b)Sets the |
| public void | setFloatable(boolean
if b)true, the tool bar can be moved;
false otherwiseSets the |
| public void | setLayout(LayoutManager mgr)
Overrides java. Sets the layout manager for this container. |
| public void | |
| public void | setOrientation(int
the new orientation -- either o)HORIZONTAL or
VERTICALSets the orientation of the tool bar. |
| public void | setRollover(boolean
true for rollover toolbar buttons; otherwise false rollover)Sets the rollover state of this toolbar. |
| public void | |
| public void | updateUI()
Overrides javax. Notification from the |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See |
| floatable | back to summary |
|---|---|
| private boolean floatable | |
| margin | back to summary |
|---|---|
| private Insets margin | |
| orientation | back to summary |
|---|---|
| private int orientation | |
| paintBorder | back to summary |
|---|---|
| private boolean paintBorder | |
| uiClassID | back to summary |
|---|---|
| private static final String uiClassID Hides javax.
| |
| JToolBar | back to summary |
|---|---|
| public JToolBar() Creates a new tool bar; orientation defaults to | |
| JToolBar | back to summary |
|---|---|
| public JToolBar(int orientation) Creates a new tool bar with the specified
| |
| JToolBar | back to summary |
|---|---|
| public JToolBar(String name) Creates a new tool bar with the specified
| |
| JToolBar | back to summary |
|---|---|
| public JToolBar(String name, int orientation) Creates a new tool bar with a specified
| |
| add | back to summary |
|---|---|
| public JButton add(Action a) Adds a new | |
| addImpl | back to summary |
|---|---|
| protected void addImpl(Component comp, Object constraints, int index) Overrides java. If a | |
| addSeparator | back to summary |
|---|---|
| public void addSeparator() Appends a separator of default size to the end of the tool bar. The default size is determined by the current look and feel. | |
| addSeparator | back to summary |
|---|---|
| public void addSeparator(Dimension size) Appends a separator of a specified size to the end of the tool bar.
| |
| checkOrientation | back to summary |
|---|---|
| private void checkOrientation(int orientation) | |
| createActionChangeListener | back to summary |
|---|---|
| protected PropertyChangeListener createActionChangeListener(JButton b) Returns a properly configured
| |
| createActionComponent | back to summary |
|---|---|
| protected JButton createActionComponent(Action a) Factory method which creates the | |
| getAccessibleContext | back to summary |
|---|---|
| public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the AccessibleContext associated with this JToolBar. For tool bars, the AccessibleContext takes the form of an AccessibleJToolBar. A new AccessibleJToolBar instance is created if necessary.
| |
| getComponentAtIndex | back to summary |
|---|---|
| public Component getComponentAtIndex(int i) Returns the component at the specified index.
| |
| getComponentIndex | back to summary |
|---|---|
| public int getComponentIndex(Component c) Returns the index of the specified component. (Note: Separators occupy index positions.)
| |
| getMargin | back to summary |
|---|---|
| public Insets getMargin() Returns the margin between the tool bar's border and its buttons. | |
| getOrientation | back to summary |
|---|---|
| public int getOrientation() Returns the current orientation of the tool bar. The value is either
| |
| getUI | back to summary |
|---|---|
| public ToolBarUI getUI() Overrides javax. Returns the tool bar's current UI. | |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| isBorderPainted | back to summary |
|---|---|
| public boolean isBorderPainted() Gets the
| |
| isFloatable | back to summary |
|---|---|
| public boolean isFloatable() Gets the
| |
| isRollover | back to summary |
|---|---|
| public boolean isRollover() Returns the rollover state.
| |
| paintBorder | back to summary |
|---|---|
| protected void paintBorder(Graphics g) Overrides javax. Paints the tool bar's border if the
| |
| paramString | back to summary |
|---|---|
| protected String paramString() Overrides javax. Returns a string representation of this
| |
| setBorderPainted | back to summary |
|---|---|
| public void setBorderPainted(boolean b) Sets the
| |
| setFloatable | back to summary |
|---|---|
| public void setFloatable(boolean b) Sets the
| |
| setLayout | back to summary |
|---|---|
| public void setLayout(LayoutManager mgr) Overrides java. Doc from java. Sets the layout manager for this container. This method changes layout-related information, and therefore, invalidates the component hierarchy. | |
| setMargin | back to summary |
|---|---|
| public void setMargin(Insets m) Sets the margin between the tool bar's border and
its buttons. Setting to
| |
| setOrientation | back to summary |
|---|---|
| public void setOrientation(int o) Sets the orientation of the tool bar. The orientation must have
either the value
| |
| setRollover | back to summary |
|---|---|
| public void setRollover(boolean rollover) Sets the rollover state of this toolbar. If the rollover state is true then the border of the toolbar buttons will be drawn only when the mouse pointer hovers over them. The default value of this property is false. The implementation of a look and feel may choose to ignore this property.
| |
| setUI | back to summary |
|---|---|
| public void setUI(ToolBarUI ui) Sets the L&F object that renders this component.
| |
| updateUI | back to summary |
|---|---|
| public void updateUI() Overrides javax. Notification from the
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Hides javax. See
| |
JToolBar class. It provides an implementation of the
Java Accessibility API appropriate to toolbar user-interface elements.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides javax. Get the role of this object. |
| public AccessibleStateSet | Returns: an instance of AccessibleStateSet containing the current state set of the objectOverrides javax. Get the state of this object. |
| AccessibleJToolBar | back to summary |
|---|---|
| protected AccessibleJToolBar() Constructs an | |
| getAccessibleRole | back to summary |
|---|---|
| public AccessibleRole getAccessibleRole() Overrides javax. Get the role of this object.
| |
| getAccessibleStateSet | back to summary |
|---|---|
| public AccessibleStateSet getAccessibleStateSet() Overrides javax. Get the state of this object.
| |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | addLayoutComponent(String name, Component comp)
Implements java. If the layout manager uses a per-component string,
adds the component |
| public void | addLayoutComponent(Component comp, Object constraints)
Implements java. Adds the specified component to the layout, using the specified constraint object. |
| public float | getLayoutAlignmentX(Container target)
Implements java. Returns the alignment along the x axis. |
| public float | getLayoutAlignmentY(Container target)
Implements java. Returns the alignment along the y axis. |
| public void | invalidateLayout(Container target)
Implements java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. |
| public void | layoutContainer(Container target)
Implements java. Lays out the specified container. |
| public Dimension | maximumLayoutSize(Container target)
Implements java. Calculates the maximum size dimensions for the specified container, given the components it contains. |
| public Dimension | minimumLayoutSize(Container target)
Implements java. Calculates the minimum size dimensions for the specified container, given the components it contains. |
| public Dimension | preferredLayoutSize(Container target)
Implements java. Calculates the preferred size dimensions for the specified container, given the components it contains. |
| public void | propertyChange(PropertyChangeEvent e)
Implements java. This method gets called when a bound property is changed. |
| public void | removeLayoutComponent(Component comp)
Implements java. Removes the specified component from the layout. |
| lm | back to summary |
|---|---|
| pack-priv BoxLayout lm | |
| DefaultToolBarLayout | back to summary |
|---|---|
| pack-priv DefaultToolBarLayout(int orientation) | |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(String name, Component comp) Implements java. Doc from java. If the layout manager uses a per-component string,
adds the component | |
| addLayoutComponent | back to summary |
|---|---|
| public void addLayoutComponent(Component comp, Object constraints) Implements java. Doc from java. Adds the specified component to the layout, using the specified constraint object. | |
| getLayoutAlignmentX | back to summary |
|---|---|
| public float getLayoutAlignmentX(Container target) Implements java. Doc from java. Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| getLayoutAlignmentY | back to summary |
|---|---|
| public float getLayoutAlignmentY(Container target) Implements java. Doc from java. Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc. | |
| invalidateLayout | back to summary |
|---|---|
| public void invalidateLayout(Container target) Implements java. Doc from java. Invalidates the layout, indicating that if the layout manager has cached information it should be discarded. | |
| layoutContainer | back to summary |
|---|---|
| public void layoutContainer(Container target) Implements java. Doc from java. Lays out the specified container. | |
| maximumLayoutSize | back to summary |
|---|---|
| public Dimension maximumLayoutSize(Container target) Implements java. Doc from java. Calculates the maximum size dimensions for the specified container, given the components it contains. | |
| minimumLayoutSize | back to summary |
|---|---|
| public Dimension minimumLayoutSize(Container target) Implements java. Doc from java. Calculates the minimum size dimensions for the specified container, given the components it contains. | |
| preferredLayoutSize | back to summary |
|---|---|
| public Dimension preferredLayoutSize(Container target) Implements java. Doc from java. Calculates the preferred size dimensions for the specified container, given the components it contains. | |
| propertyChange | back to summary |
|---|---|
| public void propertyChange(PropertyChangeEvent e) Implements java. Doc from java. This method gets called when a bound property is changed. | |
| removeLayoutComponent | back to summary |
|---|---|
| public void removeLayoutComponent(Component comp) Implements java. Doc from java. Removes the specified component from the layout. | |
| Modifier and Type | Field and Description |
|---|---|
| private Dimension |
| Access | Constructor and Description |
|---|---|
| public | Separator()
Creates a new toolbar separator with the default size as defined by the current look and feel. |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Dimension | Returns: theDimension object containing the separator's
maximum sizeOverrides javax. Returns the maximum size for the separator. |
| public Dimension | Returns: theDimension object containing the separator's
minimum sizeOverrides javax. Returns the minimum size for the separator. |
| public Dimension | Returns: theDimension object containing the separator's
preferred sizeOverrides javax. Returns the preferred size for the separator. |
| public Dimension | Returns: theDimension object containing the separator's
size (This is a reference, NOT a copy!)Returns the size of the separator |
| public String | Returns: the string "ToolBarSeparatorUI"Overrides javax. Returns the name of the L&F class that renders this component. |
| public void |
| separatorSize | back to summary |
|---|---|
| private Dimension separatorSize | |
| Separator | back to summary |
|---|---|
| public Separator() Creates a new toolbar separator with the default size as defined by the current look and feel. | |
| Separator | back to summary |
|---|---|
| public Separator(Dimension size) Creates a new toolbar separator with the specified size.
| |
| getMaximumSize | back to summary |
|---|---|
| public Dimension getMaximumSize() Overrides javax. Returns the maximum size for the separator.
| |
| getMinimumSize | back to summary |
|---|---|
| public Dimension getMinimumSize() Overrides javax. Returns the minimum size for the separator.
| |
| getPreferredSize | back to summary |
|---|---|
| public Dimension getPreferredSize() Overrides javax. Returns the preferred size for the separator.
| |
| getSeparatorSize | back to summary |
|---|---|
| public Dimension getSeparatorSize() Returns the size of the separator
| |
| getUIClassID | back to summary |
|---|---|
| public String getUIClassID() Overrides javax. Returns the name of the L&F class that renders this component.
| |
| setSeparatorSize | back to summary |
|---|---|
| public void setSeparatorSize(Dimension size) Sets the size of the separator.
| |