- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.AbstractButton
-
- javax.swing.JToggleButton
-
- All Implemented Interfaces:
-
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,SwingConstants
- 已知直接子类:
-
JCheckBox
,JRadioButton
@JavaBean(defaultProperty="UIClassID", description="An implementation of a two-state button.") public class JToggleButton extends AbstractButton implements Accessible
一个两状态按钮的实现。JRadioButton
和JCheckBox
类是JCheckBox
的子类。 有关使用它们的信息,请参阅“Java教程”中的“ How to Use Buttons, Check Boxes, and Radio Buttons ”一节。按钮可以配置,并在一定程度上由
Action
s控制。 使用带按钮的Action
除了直接配置按钮之外,还有很多好处。 有关更多详细信息,请参阅Swing Components SupportingAction
,您可以在“Java教程”一节中的 How to Use Actions中找到更多信息。警告: Swing不是线程安全的。 有关详细信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,支持所有JavaBeans的长期存储已被添加到
java.beans
包中。 请参阅XMLEncoder
。- 从以下版本开始:
- 1.2
- 另请参见:
-
JRadioButton
,JCheckBox
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 protected class
JToggleButton.AccessibleJToggleButton
该类实现JToggleButton
类的辅助功能支持。static class
JToggleButton.ToggleButtonModel
ToggleButton模型-
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from 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 描述 JToggleButton()
创建最初未选择的切换按钮,而不设置文本或图像。JToggleButton(String text)
使用指定的文本创建一个未选择的切换按钮。JToggleButton(String text, boolean selected)
创建具有指定文本和选择状态的切换按钮。JToggleButton(String text, Icon icon)
创建具有指定文本和图像的切换按钮,最初未被选择。JToggleButton(String text, Icon icon, boolean selected)
创建具有指定文本,图像和选择状态的切换按钮。JToggleButton(Action a)
创建一个切换按钮,其属性取自提供的操作。JToggleButton(Icon icon)
创建一个最初未选择的切换按钮与指定的图像,但没有文本。JToggleButton(Icon icon, boolean selected)
创建具有指定图像和选择状态但不包含文本的切换按钮。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 AccessibleContext
getAccessibleContext()
获取与此JToggleButton关联的AccessibleContext。String
getUIClassID()
返回一个字符串,指定呈现此组件的l&f类的名称。protected String
paramString()
返回此JToggleButton的字符串表示形式。void
requestFocus(FocusEvent.Cause cause)
如果此切换按钮是ButtonGroup
的成员,该另一个切换按钮被选中,并且可以是焦点所有者,并且焦点原因参数表示任何方向的窗口激活或焦点遍历操作,则方法执行的结果与在组中选择的切换按钮上调用Component.requestFocus(FocusEvent.Cause)
。boolean
requestFocusInWindow(FocusEvent.Cause cause)
如果此切换按钮是ButtonGroup
的成员,该另一个切换按钮被选中并且可以是焦点所有者,并且焦点原因参数表示任何方向的窗口激活或焦点遍历动作,则方法执行的结果与在组中选择的切换按钮上调用Component.requestFocusInWindow(FocusEvent.Cause)
。void
updateUI()
将UI属性重置为当前外观的值。-
Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
-
Methods inherited from 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, 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, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Methods inherited from 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, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class 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, 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, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
-
-
-
构造方法详细信息
-
JToggleButton
public JToggleButton()
创建最初未选择的切换按钮,而不设置文本或图像。
-
JToggleButton
public JToggleButton(Icon icon)
创建一个最初未选择的切换按钮与指定的图像,但没有文本。- 参数
-
icon
- 按钮应该显示的图像
-
JToggleButton
public JToggleButton(Icon icon, boolean selected)
创建具有指定图像和选择状态但不包含文本的切换按钮。- 参数
-
icon
- 按钮应该显示的图像 -
selected
- 如果为true,则初始选择该按钮; 否则,该按钮最初未被选择
-
JToggleButton
public JToggleButton(String text)
使用指定的文本创建一个未选择的切换按钮。- 参数
-
text
- 显示在切换按钮上的字符串
-
JToggleButton
public JToggleButton(String text, boolean selected)
创建具有指定文本和选择状态的切换按钮。- 参数
-
text
- 显示在切换按钮上的字符串 -
selected
- 如果为true,则初始选择该按钮; 否则,该按钮最初未被选择
-
JToggleButton
public JToggleButton(Action a)
创建一个切换按钮,其属性取自提供的操作。- 参数
-
a
-一个实例Action
- 从以下版本开始:
- 1.3
-
JToggleButton
public JToggleButton(String text, Icon icon)
创建具有指定文本和图像的切换按钮,最初未被选择。- 参数
-
text
- 按钮上显示的字符串 -
icon
- 按钮应该显示的图像
-
-
方法详细信息
-
updateUI
public void updateUI()
将UI属性重置为当前外观的值。- 重写:
-
updateUI
中的AbstractButton
- 另请参见:
-
JComponent.updateUI()
-
getUIClassID
@BeanProperty(bound=false, description="A string that specifies the name of the L&F class") public String getUIClassID()
返回一个字符串,指定呈现此组件的l&f类的名称。- 重写:
-
getUIClassID
中的JComponent
- 结果
- 字符串“ToggleButtonUI”
- 另请参见:
-
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
requestFocus
public void requestFocus(FocusEvent.Cause cause)
如果此切换按钮是ButtonGroup
的成员,该另一个切换按钮被选中并且可以是焦点所有者,并且焦点原因参数表示任何方向的窗口激活或焦点遍历动作,则方法执行的结果与在组中选择的切换按钮上调用Component.requestFocus(FocusEvent.Cause)
。 在所有其他情况下,该方法的结果与在此切换按钮上调用Component.requestFocus(FocusEvent.Cause)
相同。- 重写:
-
requestFocus
在Component
- 参数
-
cause
- 要求重点的原因 - 从以下版本开始:
- 9
- 另请参见:
-
ButtonGroup
,Component.requestFocus(FocusEvent.Cause)
,FocusEvent.Cause
-
requestFocusInWindow
public boolean requestFocusInWindow(FocusEvent.Cause cause)
如果此切换按钮是ButtonGroup
的成员,该另一个切换按钮被选中并且可以是焦点所有者,并且焦点原因参数表示任何方向的窗口激活或焦点遍历动作,则方法执行的结果与在组中选择的切换按钮上调用Component.requestFocusInWindow(FocusEvent.Cause)
。 在所有其他情况下,该方法的结果与在此切换按钮上调用Component.requestFocusInWindow(FocusEvent.Cause)
相同。- 重写:
-
requestFocusInWindow
在Component
- 参数
-
cause
- 要求焦点的原因 - 结果
-
false
如果焦点更改请求保证失败;true
如果有可能成功 - 从以下版本开始:
- 9
- 另请参见:
-
ButtonGroup
,Component.requestFocusInWindow(FocusEvent.Cause)
,FocusEvent.Cause
-
paramString
protected String paramString()
返回此JToggleButton的字符串表示形式。 该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null
。- 重写:
-
paramString
在AbstractButton
- 结果
- 这个JToggleButton的字符串表示形式。
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this ToggleButton.") public AccessibleContext getAccessibleContext()
获取与此JToggleButton关联的AccessibleContext。 对于切换按钮,AccessibleContext采用AccessibleJToggleButton的形式。 如有必要,将创建一个新的AccessibleJToggleButton实例。- Specified by:
-
getAccessibleContext
在接口Accessible
- 重写:
-
getAccessibleContext
在Component
- 结果
- an AccessibleJToggleButton that serves as the AccessibleContext of this JToggleButton
-
-