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 或控件。有关使用工具栏的示例和信息,请参阅 如何使用工具栏,The Java Tutorial 中的一个部分。
对于大多数外观,用户可以将工具栏拖出到单独的窗口中(除非 floatable 属性设置为 false )。为了使拖出正常工作,建议您将 JToolBar 实例添加到布局管理器为 BorderLayout 的容器的四个“边”之一,并且不要将子实例添加到其他四个“边”中的任何一个。
Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略。
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
- 自从:
- 1.2
- 参见:
-
内部类总结
内部类修饰符和类型类描述protected class此类实现了对JToolBar类的辅助功能支持。static class特定于工具栏的分隔符。在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
在类 javax.swing.JComponent 中声明的字段
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW在类 java.awt.Component 中声明的字段
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT在接口 java.awt.image.ImageObserver 中声明的字段
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH在接口 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 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述添加一个新的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。voidsetFloatable(boolean b) 设置floatable属性,该属性必须为true以便用户移动工具栏。void设置工具栏边框与其按钮之间的边距。voidsetOrientation(int o) 设置工具栏的方向。voidsetRollover(boolean rollover) 设置此工具栏的翻转状态。void设置呈现此组件的 L&F 对象。voidupdateUI()来自UIFactory的通知,L&F 已更改。在类 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, 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, setLayout, 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, 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
-
构造方法详细信息
-
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
-
-
方法详情
-
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 已更改。调用以将 UI 替换为来自UIFactory的最新版本。- 重写:
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- 如果为真,则绘制边框- 参见:
-
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) 设置此工具栏的翻转状态。如果翻转状态为真,则仅当鼠标指针悬停在工具栏按钮上时才会绘制工具栏按钮的边框。此属性的默认值为 false。外观的实现可能会选择忽略此属性。
- 参数:
rollover- 鼠标悬停工具栏按钮为真;否则为假- 自从:
- 1.4
-
isRollover
public boolean isRollover()返回翻转状态。- 返回:
- 如果要绘制悬停工具栏按钮,则为 true;否则为假
- 自从:
- 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
-