java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JToolBar
- 所有已实现的接口:
-
ImageObserver,MenuContainer,Serializable,Accessible,SwingConstants
@JavaBean(defaultProperty="UI", description="A component which displays commonly used controls or Actions.") public class JToolBar extends JComponent implements SwingConstants, Accessible
JToolBar提供了一个用于显示常用Action或控件的组件。有关示例和使用工具栏的信息,请参阅如何使用工具栏,这是Java教程中的一个部分。
在大多数外观和感觉中,用户可以将工具栏拖出到一个单独的窗口中(除非将floatable属性设置为false)。为了使拖动正常工作,建议将JToolBar实例添加到布局管理器为BorderLayout的容器的四个“边”之一,并且不要将子项添加到其他四个“边”中的任何一个。
警告: Swing不是线程安全的。更多信息请参见Swing的线程策略。
警告: 该类的序列化对象将不兼容未来的Swing版本。当前的序列化支持适用于短期存储或在运行相同Swing版本的应用程序之间的RMI。从1.4版本开始,已将所有JavaBeans的长期存储支持添加到java.beans包中。请参见XMLEncoder。
- 自从:
- 1.2
- 另请参阅:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class该类为JToolBar类实现了辅助功能支持。static class一个特定于工具栏的分隔符。Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields declared in interface 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription添加一个新的分发动作的JButton。protected void如果正在添加一个JButton,则最初将其设置为禁用状态。void在工具栏末尾附加默认大小的分隔符。voidaddSeparator(Dimension size) 在工具栏末尾附加指定大小的分隔符。protected PropertyChangeListener返回一个正确配置的PropertyChangeListener,当Action发生更改时更新控件,如果希望使用控件的默认属性更改监听器,则返回null。protected JButton工厂方法,为添加到JToolBar的Action创建JButton。获取与此JToolBar关联的AccessibleContext。getComponentAtIndex(int i) 返回指定索引处的组件。int返回指定组件的索引。返回工具栏边框与其按钮之间的边距。int返回工具栏的当前方向。getUI()返回工具栏的当前UI。返回呈现此组件的L&F类的名称。boolean获取borderPainted属性。boolean获取floatable属性。boolean返回鼠标悬停状态。protected void如果borderPainted属性为true,则绘制工具栏的边框。protected String返回此JToolBar的字符串表示形式。voidsetBorderPainted(boolean b) 设置borderPainted属性,如果应绘制边框,则为true。此属性的默认值为true。某些外观和感觉可能不实现绘制边框;它们将忽略此属性。voidsetFloatable(boolean b) 设置floatable属性,用户必须将其设置为true才能移动工具栏。void设置工具栏边框与其按钮之间的边距。voidsetOrientation(int o) 设置工具栏的方向。voidsetRollover(boolean rollover) 设置此工具栏的鼠标悬停状态。void设置呈现此组件的L&F对象。voidupdateUI()来自UIFactory的通知,L&F已更改。Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, updateMethods declared in class 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, setLayout, transferFocusDownCycle, validate, validateTreeMethods declared in class 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JToolBar
public JToolBar()创建一个新的工具栏;方向默认为HORIZONTAL。 -
JToolBar
public JToolBar(int orientation) 创建一个具有指定orientation的新工具栏。orientation必须是HORIZONTAL或VERTICAL之一。- 参数:
-
orientation- 所需的方向
-
JToolBar
创建一个具有指定name的新工具栏。该名称用作未停靠工具栏的标题。默认方向为HORIZONTAL。- 参数:
-
name- 工具栏的名称 - 自从:
- 1.3
-
JToolBar
创建一个具有指定name和orientation的新工具栏。所有其他构造函数都调用此构造函数。如果orientation是无效值,则会抛出异常。- 参数:
-
name- 工具栏的名称 -
orientation- 初始方向 -- 必须是HORIZONTAL或VERTICAL之一 - 抛出:
-
IllegalArgumentException- 如果方向既不是HORIZONTAL也不是VERTICAL - 自从:
- 1.3
-
-
Method Details
-
getUI
返回工具栏的当前UI。- 覆盖:
-
getUI在类JComponent中 - 返回:
- 工具栏的当前UI。
- 另请参阅:
-
setUI
@BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the Component\'s LookAndFeel.") public void setUI(ToolBarUI ui) 设置呈现此组件的L&F对象。- 参数:
-
ui-ToolBarUIL&F对象 - 另请参阅:
-
updateUI
public void updateUI()来自UIFactory的通知,L&F已更改。调用以使用最新版本从UIFactory替换UI。- 覆盖:
-
updateUI在类JComponent中 - 另请参阅:
-
getUIClassID
返回呈现此组件的L&F类的名称。- 覆盖:
-
getUIClassID在类JComponent中 - 返回:
- 字符串"ToolBarUI"
- 另请参阅:
-
getComponentIndex
返回指定组件的索引。(注意:分隔符占据索引位置。)- 参数:
-
c- 要查找的Component - 返回:
- 一个整数,表示组件的位置,其中0是第一个
-
getComponentAtIndex
返回指定索引处的组件。- 参数:
-
i- 组件的位置,其中0是第一个 - 返回:
-
该位置处的
Component,对于无效索引返回null
-
setMargin
@BeanProperty(expert=true, description="The margin between the tool bar\'s border and contents") public void setMargin(Insets m) 设置工具栏边框与其按钮之间的边距。将其设置为null会导致工具栏使用默认边距。工具栏的默认Border对象使用此值来创建适当的边距。但是,如果在工具栏上设置了非默认边框,则该Border对象负责创建适当的边距空间(否则此属性将被忽略)。- 参数:
-
m- 定义边框和按钮之间空间的Insets对象 - 另请参阅:
-
getMargin
返回工具栏边框与其按钮之间的边距。- 返回:
-
包含边距值的
Insets对象 - 另请参阅:
-
isBorderPainted
public boolean isBorderPainted()获取borderPainted属性。- 返回:
-
borderPainted属性的值 - 另请参阅:
-
setBorderPainted
@BeanProperty(expert=true, description="Does the tool bar paint its borders?") public void setBorderPainted(boolean b) 设置borderPainted属性,如果应绘制边框,则为true。此属性的默认值为true。某些外观和感觉可能不实现绘制边框;它们将忽略此属性。- 参数:
-
b- 如果为true,则绘制边框 - 另请参阅:
-
paintBorder
如果borderPainted属性为true,则绘制工具栏的边框。- 覆盖:
-
paintBorder在类JComponent中 - 参数:
-
g- 进行绘制的Graphics上下文 - 另请参阅:
-
isFloatable
public boolean isFloatable()获取floatable属性。- 返回:
-
floatable属性的值 - 另请参阅:
-
setFloatable
@BeanProperty(preferred=true, description="Can the tool bar be made to float by the user?") public void setFloatable(boolean b) 设置floatable属性,必须为true才能使用户移动工具栏。通常,可移动工具栏可以在同一容器内拖动到不同位置或拖动到自己的窗口中。此属性的默认值为true。某些外观和感觉可能不实现可移动工具栏;它们将忽略此属性。- 参数:
-
b- 如果为true,则工具栏可以移动;否则为false - 另请参阅:
-
getOrientation
public int getOrientation()返回工具栏的当前方向。该值为HORIZONTAL或VERTICAL。- 返回:
-
代表当前方向的整数 -- 可能为
HORIZONTAL或VERTICAL - 另请参阅:
-
setOrientation
@BeanProperty(preferred=true, enumerationValues={"SwingConstants.HORIZONTAL","SwingConstants.VERTICAL"}, description="The current orientation of the tool bar") public void setOrientation(int o) 设置工具栏的方向。方向必须为HORIZONTAL或VERTICAL之一。如果orientation是无效值,则会抛出异常。- 参数:
-
o- 新方向 -- 可能为HORIZONTAL或VERTICAL - 抛出:
-
IllegalArgumentException- 如果方向既不是HORIZONTAL也不是VERTICAL - 另请参阅:
-
setRollover
@BeanProperty(preferred=true, visualUpdate=true, description="Will draw rollover button borders in the toolbar.") public void setRollover(boolean rollover) 设置此工具栏的鼠标悬停状态。如果鼠标悬停状态为true,则仅在鼠标指针悬停在按钮上时才绘制工具栏按钮的边框。此属性的默认值为false。外观和感觉的实现可能选择忽略此属性。
- 参数:
-
rollover- 为鼠标悬停工具栏按钮为true;否则为false - 自:
- 1.4
-
isRollover
public boolean isRollover()返回鼠标悬停状态。- 返回:
- 如果要绘制鼠标悬停工具栏按钮,则为true;否则为false
- 自:
- 1.4
- 另请参阅:
-
addSeparator
public void addSeparator()在工具栏末尾添加默认大小的分隔符。默认大小由当前外观和感觉确定。 -
addSeparator
在工具栏末尾添加指定大小的分隔符。- 参数:
-
size- 分隔符的Dimension
-
add
添加一个新的JButton,用于分派操作。- 参数:
-
a- 要添加为新菜单项的Action对象 - 返回:
- 分派操作的新按钮
-
createActionComponent
工厂方法,为添加到JToolBar的Action创建JButton。如果传递了一个null操作,则默认名称为空。- 参数:
-
a- 要添加的按钮的Action - 返回:
- 新创建的按钮
- 自:
- 1.3
- 另请参阅:
-
createActionChangeListener
返回一个正确配置的PropertyChangeListener,当Action发生更改时更新控件,如果需要默认的控件属性更改监听器,则返回null。- 参数:
-
b- 一个JButton - 返回:
-
null
-
addImpl
如果正在添加一个JButton,则初始设置为禁用状态。 -
paramString
返回此JToolBar的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不会为null。- 覆盖:
-
paramString在类JComponent中 - 返回:
-
此
JToolBar的字符串表示形式。
-
getAccessibleContext
获取与此JToolBar关联的AccessibleContext。对于工具栏,AccessibleContext采用AccessibleJToolBar的形式。如果需要,将创建一个新的AccessibleJToolBar实例。- 指定者:
-
getAccessibleContext在接口Accessible中 - 覆盖:
-
getAccessibleContext在类Component中 - 返回:
- 作为此JToolBar的AccessibleContext的AccessibleJToolBar
-