javax.swing

接口
异常
java.lang.Object
  继承者 java.awt.Component
      继承者 java.awt.Container
          继承者 javax.swing.JComponent
              继承者 javax.swing.JToolBar
所有已实现的接口:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class JToolBar
     
extends JComponent
implements SwingConstants, Accessible

JToolBar 提供了一个用来显示常用的 Action 或控件的组件。有关使用工具栏的示例和信息,请参阅 The Java Tutorial 中的 How to Use Tool Bars 一节。

对于大多数的外观,用户可以将工具栏拖到单独的窗口中(除非 floatable 属性被设置为 false)。为了正确执行拖动,建议将 JToolBar 实例添加到容器的四“边”中的一边(其中容器的布局管理器为 BorderLayout),并且不在其他四“边”中添加任何子级。

警告:Swing 不是线程安全的。有关更多信息,请参阅 Swing's Threading Policy

警告:此类的已序列化对象与以后的 Swing 版本不兼容。当前序列化支持适用于短期存储,或适用于在运行相同 Swing 版本的应用程序之间进行 RMI(Remote Method Invocation,远程方法调用)。从 1.4 版本开始,已在 java.beans 包中添加了支持所有 JavaBeansTM 长期存储的功能。请参见 XMLEncoder

另请参见:
Action

嵌套类摘要
protected  class JToolBar.AccessibleJToolBar
          此类实现对 JToolBar 类的可访问性支持。
static class JToolBar.Separator
          一个特定于工具栏的分隔符。
 
从类 javax.swing.JComponent 继承的嵌套类/接口
JComponent.AccessibleJComponent
 
从类 java.awt.Container 继承的嵌套类/接口
Container.AccessibleAWTContainer
 
从类 java.awt.Component 继承的嵌套类/接口
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
字段摘要
 
从类 javax.swing.JComponent 继承的字段
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
从类 java.awt.Component 继承的字段
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
从接口 javax.swing.SwingConstants 继承的字段
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
从接口 java.awt.image.ImageObserver 继承的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
构造方法摘要
JToolBar()
          创建新的工具栏;默认的方向为 HORIZONTAL
JToolBar(int orientation)
          创建具有指定 orientation 的新工具栏。
JToolBar(String name)
          创建一个具有指定 name 的新工具栏。
JToolBar(String name, int orientation)
          创建一个具有指定 nameorientation 的新工具栏。
 
方法摘要
 JButton add(Action a)
          添加一个指派动作的新的 JButton
protected  void addImpl(Component comp, Object constraints, int index)
          在添加 JButton 时,它最初被设置为 disabled。
 void addSeparator()
          将默认大小的分隔符添加到工具栏的末尾。
 void addSeparator(Dimension size)
          将指定大小的分隔符添加到工具栏的末尾。
protected  PropertyChangeListener createActionChangeListener(JButton b)
          返回正确配置的 PropertyChangeListener,它根据 Action 的更改对控件进行更新,如果需要使用默认的属性更改侦听器,则为 null
protected  JButton createActionComponent(Action a)
          将为 Action 创建 JButton 的工厂方法添加到 JToolBar 中。
 AccessibleContext getAccessibleContext()
          获取与此 JToolBar 关联的 AccessibleContext。
 Component getComponentAtIndex(int i)
          返回指定索引位置的组件。
 int getComponentIndex(Component c)
          返回指定组件的索引。
 Insets getMargin()
          返回工具栏边框和它的按钮之间的空白。
 int getOrientation()
          返回工具栏的当前方向。
 ToolBarUI getUI()
          返回工具栏的当前 UI。
 String getUIClassID()
          返回呈现此组件的 L&F 类的名称。
 boolean isBorderPainted()
          获取 borderPainted 属性。
 boolean isFloatable()
          获取 floatable 属性。
 boolean isRollover()
          返回 rollover 状态。
protected  void paintBorder(Graphics g)
          如果 borderPainted 属性为 true,则绘制工具栏边框。
protected  String paramString()
          返回此 JToolBar 的字符串表示形式。
 void setBorderPainted(boolean b)
          设置 borderPainted 属性,如果需要绘制边框,则此属性为 true
 void setFloatable(boolean b)
          设置 floatable 属性,如果要移动工具栏,此属性必须设置为 true
 void setLayout(LayoutManager mgr)
          设置此容器的布局管理器。
 void setMargin(Insets m)
          设置工具栏边框和它的按钮之间的空白。
 void setOrientation(int o)
          设置工具栏的方向。
 void setRollover(boolean rollover)
          设置此工具栏的 rollover 状态。
 void setUI(ToolBarUI ui)
          设置呈现此组件的 L&F 对象。
 void updateUI()
          UIFactory 发出的关于 L&F 已更改的通知。
 
从类 javax.swing.JComponent 继承的方法
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
从类 java.awt.Container 继承的方法
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
从类 java.awt.Component 继承的方法
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

构造方法详细信息

JToolBar

public JToolBar()
创建新的工具栏;默认的方向为 HORIZONTAL


JToolBar

public JToolBar(int orientation)
创建具有指定 orientation 的新工具栏。 orientation 不是 HORIZONTAL 就是 VERTICAL

参数:
orientation - 预期的方向

JToolBar

public JToolBar(String name)
创建一个具有指定 name 的新工具栏。名称用作浮动式 (undocked) 工具栏的标题。默认的方向为 HORIZONTAL

参数:
name - 工具栏的名称
从以下版本开始:
1.3

JToolBar

public JToolBar(String name,
                int orientation)
创建一个具有指定 nameorientation 的新工具栏。所有其他构造方法均调用此构造方法。如果 orientation 是一个无效值,则将抛出异常。

参数:
name - 工具栏的名称
orientation - 初始方向,它不是 HORIZONTAL 就是 VERTICAL
抛出:
IllegalArgumentException - 如果方向既不是 HORIZONTAL 也不是 VERTICAL
从以下版本开始:
1.3
方法详细信息

getUI

public ToolBarUI getUI()
返回工具栏的当前 UI。

另请参见:
setUI(javax.swing.plaf.ToolBarUI)

setUI

public void setUI(ToolBarUI ui)
设置呈现此组件的 L&F 对象。

参数:
ui - ToolBarUI L&F 对象
另请参见:
UIDefaults.getUI(javax.swing.JComponent)