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".
| Methods from java.awt.Component: |
|---|
|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventTypeEnabled, findNextFocusComponent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, generateName, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getGraphicsConfigurationImpl, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setPeer, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, translateEvent, update, validate |
| Method from javax.swing.JToolBar Detail: |
public JButton add(Action a) {
JButton b = createActionComponent(a);
b.setAction(a);
add(b);
return b;
}
Adds a new JButton which dispatches the action. |
protected void addImpl(Component comp,
Object constraints,
int index) {
if (comp instanceof Separator) {
if (getOrientation() == VERTICAL) {
( (Separator)comp ).setOrientation(JSeparator.HORIZONTAL);
} else {
( (Separator)comp ).setOrientation(JSeparator.VERTICAL);
}
}
super.addImpl(comp, constraints, index);
if (comp instanceof JButton) {
((JButton)comp).setDefaultCapable(false);
}
}
If a JButton is being added, it is initially
set to be disabled. |
public void addSeparator() {
addSeparator(null);
}
Appends a separator of default size to the end of the tool bar.
The default size is determined by the current look and feel. |
public void addSeparator(Dimension size) {
JToolBar.Separator s = new JToolBar.Separator( size );
add(s);
}
Appends a separator of a specified size to the end
of the tool bar. |
protected PropertyChangeListener createActionChangeListener(JButton b) {
return null;
}
Returns a properly configured PropertyChangeListener
which updates the control as changes to the Action occur,
or null if the default
property change listener for the control is desired. |
protected JButton createActionComponent(Action a) {
JButton b = new JButton() {
protected PropertyChangeListener createActionPropertyChangeListener(Action a) {
PropertyChangeListener pcl = createActionChangeListener(this);
if (pcl==null) {
pcl = super.createActionPropertyChangeListener(a);
}
return pcl;
}
};
if (a != null && (a.getValue(Action.SMALL_ICON) != null ||
a.getValue(Action.LARGE_ICON_KEY) != null)) {
b.setHideActionText(true);
}
b.setHorizontalTextPosition(JButton.CENTER);
b.setVerticalTextPosition(JButton.BOTTOM);
return b;
}
Factory method which creates the JButton for
Actions added to the JToolBar.
The default name is empty if a null action is passed. |
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJToolBar();
}
return accessibleContext;
}
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. |
public Component getComponentAtIndex(int i) {
int ncomponents = this.getComponentCount();
if ( i >= 0 && i < ncomponents) {
Component[] component = this.getComponents();
return component[i];
}
return null;
}
Returns the component at the specified index. |
public int getComponentIndex(Component c) {
int ncomponents = this.getComponentCount();
Component[] component = this.getComponents();
for (int i = 0 ; i < ncomponents ; i++) {
Component comp = component[i];
if (comp == c)
return i;
}
return -1;
}
Returns the index of the specified component.
(Note: Separators occupy index positions.) |
public Insets getMargin() {
if(margin == null) {
return new Insets(0,0,0,0);
} else {
return margin;
}
}
Returns the margin between the tool bar's border and
its buttons. |
public int getOrientation() {
return this.orientation;
}
Returns the current orientation of the tool bar. The value is either
HORIZONTAL or VERTICAL. |
public ToolBarUI getUI() {
return (ToolBarUI)ui;
}
Returns the tool bar's current UI. |
public String getUIClassID() {
return uiClassID;
}
Returns the name of the L&F class that renders this component. |
public boolean isBorderPainted() {
return paintBorder;
}
Gets the borderPainted property. |
public boolean isFloatable() {
return floatable;
}
Gets the floatable property. |
public boolean isRollover() {
Boolean rollover = (Boolean)getClientProperty("JToolBar.isRollover");
if (rollover != null) {
return rollover.booleanValue();
}
return false;
}
Returns the rollover state. |
protected void paintBorder(Graphics g) {
if (isBorderPainted())
{
super.paintBorder(g);
}
}
Paints the tool bar's border if the borderPainted property
is true. |
protected String paramString() {
String paintBorderString = (paintBorder ?
"true" : "false");
String marginString = (margin != null ?
margin.toString() : "");
String floatableString = (floatable ?
"true" : "false");
String orientationString = (orientation == HORIZONTAL ?
"HORIZONTAL" : "VERTICAL");
return super.paramString() +
",floatable=" + floatableString +
",margin=" + marginString +
",orientation=" + orientationString +
",paintBorder=" + paintBorderString;
}
Returns a string representation of this JToolBar.
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null. |
public void setBorderPainted(boolean b) {
if ( paintBorder != b )
{
boolean old = paintBorder;
paintBorder = b;
firePropertyChange("borderPainted", old, b);
revalidate();
repaint();
}
}
Sets the borderPainted property, which is
true if the border should be painted.
The default value for this property is true.
Some look and feels might not implement painted borders;
they will ignore this property. |
public void setFloatable(boolean b) {
if ( floatable != b )
{
boolean old = floatable;
floatable = b;
firePropertyChange("floatable", old, b);
revalidate();
repaint();
}
}
Sets the floatable property,
which must be true for the user to move the tool bar.
Typically, a floatable tool bar can be
dragged into a different position within the same container
or out into its own window.
The default value of this property is true.
Some look and feels might not implement floatable tool bars;
they will ignore this property. |
public void setLayout(LayoutManager mgr) {
LayoutManager oldMgr = getLayout();
if (oldMgr instanceof PropertyChangeListener) {
removePropertyChangeListener((PropertyChangeListener)oldMgr);
}
super.setLayout(mgr);
}
|
public void setMargin(Insets m) {
Insets old = margin;
margin = m;
firePropertyChange("margin", old, m);
revalidate();
repaint();
}
Sets the margin between the tool bar's border and
its buttons. Setting to null causes the tool bar to
use the default margins. The tool bar's default Border
object uses this value to create the proper margin.
However, if a non-default border is set on the tool bar,
it is that Border object's responsibility to create the
appropriate margin space (otherwise this property will
effectively be ignored). |
public void setOrientation(int o) {
checkOrientation( o );
if ( orientation != o )
{
int old = orientation;
orientation = o;
firePropertyChange("orientation", old, o);
revalidate();
repaint();
}
}
Sets the orientation of the tool bar. The orientation must have
either the value HORIZONTAL or VERTICAL.
If orientation is
an invalid value, an exception will be thrown. |
public void setRollover(boolean rollover) {
putClientProperty("JToolBar.isRollover",
rollover ? Boolean.TRUE : Boolean.FALSE);
}
|
public void setUI(ToolBarUI ui) {
super.setUI(ui);
}
Sets the L&F object that renders this component. |
public void updateUI() {
setUI((ToolBarUI)UIManager.getUI(this));
// GTKLookAndFeel installs a different LayoutManager, and sets it
// to null after changing the look and feel, so, install the default
// if the LayoutManager is null.
if (getLayout() == null) {
setLayout(new DefaultToolBarLayout(getOrientation()));
}
invalidate();
}
Notification from the UIFactory that the L&F has changed.
Called to replace the UI with the latest version from the
UIFactory. |