-
- All Implemented Interfaces:
-
ImageObserver
,ItemSelectable
,MenuContainer
,Serializable
,Accessible
,SwingConstants
@JavaBean(description="A component which can be selected or deselected.") public class JCheckBox extends JToggleButton implements Accessible
复选框的实现 - 可以选择或取消选择的项目,并向用户显示其状态。 按照惯例,可以选择组中的任意数量的复选框。 有关使用复选框的示例和信息,请参阅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
, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 描述 protected class
JCheckBox.AccessibleJCheckBox
这个类实现JCheckBox
类的可访问性支持。-
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
-
Nested classes/interfaces inherited from class javax.swing.JToggleButton
JToggleButton.AccessibleJToggleButton, JToggleButton.ToggleButtonModel
-
-
Field Summary
Fields Modifier and Type Field 描述 static String
BORDER_PAINTED_FLAT_CHANGED_PROPERTY
标识对平面属性的更改。-
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 描述 JCheckBox()
创建一个最初未选择的复选框按钮,没有文字,没有图标。JCheckBox(String text)
创建一个最初未选择的复选框与文本。JCheckBox(String text, boolean selected)
创建一个带有文本的复选框,并指定是否最初选择它。JCheckBox(String text, Icon icon)
使用指定的文本和图标创建最初未选择的复选框。JCheckBox(String text, Icon icon, boolean selected)
创建一个带有文本和图标的复选框,并指定是否最初选择它。JCheckBox(Action a)
创建一个复选框,其中从提供的操作中获取属性。JCheckBox(Icon icon)
创建一个带有图标的最初未选中的复选框。JCheckBox(Icon icon, boolean selected)
创建一个带有图标的复选框,并指定是否最初选择它。
-
方法摘要
所有方法 接口方法 具体的方法 Modifier and Type 方法 描述 AccessibleContext
getAccessibleContext()
获取与此JCheckBox关联的AccessibleContext。String
getUIClassID()
返回一个字符串,它指定呈现此组件的L&F类的名称。boolean
isBorderPaintedFlat()
获取borderPaintedFlat
属性的值。protected String
paramString()
返回此JCheckBox的字符串表示形式。void
setBorderPaintedFlat(boolean b)
设置borderPaintedFlat
属性,它提供了对复选框边框的外观的看法和感觉。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
-
Methods inherited from class javax.swing.JToggleButton
requestFocus, requestFocusInWindow
-
-
-
-
字段详细信息
-
BORDER_PAINTED_FLAT_CHANGED_PROPERTY
public static final String BORDER_PAINTED_FLAT_CHANGED_PROPERTY
标识对平面属性的更改。- 另请参见:
- Constant Field Values
-
-
构造方法详细信息
-
JCheckBox
public JCheckBox()
创建一个最初未选择的复选框按钮,没有文字,没有图标。
-
JCheckBox
public JCheckBox(Icon icon)
创建一个带有图标的最初未选中的复选框。- 参数
-
icon
- 要显示的图标图像
-
JCheckBox
public JCheckBox(Icon icon, boolean selected)
创建一个带有图标的复选框,并指定是否最初选择它。- 参数
-
icon
- 要显示的图标图像 -
selected
- 表示初始选择状态的布尔值。 如果选择true
复选框
-
JCheckBox
public JCheckBox(String text)
创建一个最初未选择的复选框与文本。- 参数
-
text
- 复选框的文本。
-
JCheckBox
public JCheckBox(Action a)
创建一个复选框,其中从提供的操作中获取属性。- 参数
-
a
-Action
用于指定新的复选框 - 从以下版本开始:
- 1.3
-
JCheckBox
public JCheckBox(String text, boolean selected)
创建一个带有文本的复选框,并指定是否最初选择它。- 参数
-
text
- 复选框的文本。 -
selected
- 表示初始选择状态的布尔值。 如果选择true
复选框
-
JCheckBox
public JCheckBox(String text, Icon icon)
使用指定的文本和图标创建最初未选择的复选框。- 参数
-
text
- 复选框的文本。 -
icon
- 要显示的图标图像
-
-
方法详细信息
-
setBorderPaintedFlat
@BeanProperty(visualUpdate=true, description="Whether the border is painted flat.") public void setBorderPaintedFlat(boolean b)
设置borderPaintedFlat
属性,它提供了对复选框边框外观的看法和感觉。 这通常是设定为true
当JCheckBox
实例中的组分用作渲染诸如JTable
或JTree
。borderPaintedFlat
属性的默认值为false
。 此方法触发属性更改事件。 有些外观和感觉可能不会实现平坦的边界; 他们将忽略此属性。- 参数
-
b
-true
要求边框画成平面;false
请求正常边界 - 从以下版本开始:
- 1.3
- 另请参见:
-
isBorderPaintedFlat()
-
isBorderPaintedFlat
public boolean isBorderPaintedFlat()
获取borderPaintedFlat
属性的值。- 结果
-
该值为
borderPaintedFlat
属性 - 从以下版本开始:
- 1.3
- 另请参见:
-
setBorderPaintedFlat(boolean)
-
updateUI
public void updateUI()
将UI属性重置为当前外观的值。- 重写:
-
updateUI
在JToggleButton
- 另请参见:
-
JComponent.updateUI()
-
getUIClassID
@BeanProperty(bound=false, expert=true, description="A string that specifies the name of the L&F class") public String getUIClassID()
返回一个字符串,它指定呈现此组件的L&F类的名称。- 重写:
-
getUIClassID
在JToggleButton
- 结果
- 字符串“CheckBoxUI”
- 另请参见:
-
JComponent.getUIClassID()
,UIDefaults.getUI(javax.swing.JComponent)
-
paramString
protected String paramString()
返回此JCheckBox的字符串表示形式。 该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。 返回的字符串可能为空,但可能不是null
。 JFC组件的具体新方面。- 重写:
-
paramString
在JToggleButton
- 结果
- 这个JCheckBox的字符串表示形式。
-
getAccessibleContext
@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this CheckBox.") public AccessibleContext getAccessibleContext()
获取与此JCheckBox关联的AccessibleContext。 对于JCheckBoxes,AccessibleContext采用AccessibleJCheckBox的形式。 如有必要,将创建一个新的AccessibleJCheckBox实例。- Specified by:
-
getAccessibleContext
在接口Accessible
- 重写:
-
getAccessibleContext
在JToggleButton
- 结果
- 一个AccessibleJCheckBox作为这个JCheckBox的AccessibleContext
-
-