JavaTM 2 Platform
Standard Ed. 6

javax.swing
類別 JCheckBoxMenuItem

java.lang.Object
  繼承者 java.awt.Component
      繼承者 java.awt.Container
          繼承者 javax.swing.JComponent
              繼承者 javax.swing.AbstractButton
                  繼承者 javax.swing.JMenuItem
                      繼承者 javax.swing.JCheckBoxMenuItem
所有已實作的介面:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants

public class JCheckBoxMenuItem
extends JMenuItem
implements SwingConstants, Accessible

可以被選定或取消選定的選單項。如果被選定,選單項的旁邊通常會出現一個複選標記。如果未被選定或被取消選定,選單項的旁邊就沒有複選標記。像常規選單項一樣,複選框選單項可以有與之關聯的文本或圖標,或者二者兼而有之。

isSelected/setSelectedgetState/setState 都可以用來確定/指定選單項的選擇狀態。首選方法是 isSelectedsetSelected,它們可用於所有選單和按鈕。getStatesetState 方法用於與其他元件集的相容性。

通過 Action 可配置按鈕,並進行某種程度的控制。將 Action 用於選單項具有許多直接配置選單項所不及的優點。有關更多詳細資訊,請參閱支持 Action 的 Swing 元件,可在 The Java Tutorial 中的 How to Use Actions 一節找到更多資訊。

有關使用複選框選單項的更多資訊和範例,請參閱 The Java Tutorial 中的 How to Use Menus 一節。

警告: Swing 不是執行緒安全的。有關更多資訊,請參閱 Swing's Threading Policy

警告:此類別的序列化物件與以後的 Swing 版本不相容。當前序列化支持適用於短期存儲,或適用於在運行相同 Swing 版本的應用程序之間進行 RMI(Remote Method Invocation,遠端方法調用)。從 1.4 版本開始,已在 java.beans 套件中添加了支持所有 JavaBeansTM 長期存儲的功能。請參見 XMLEncoder


巢狀類別摘要
protected  class JCheckBoxMenuItem.AccessibleJCheckBoxMenuItem
          此類別實作對 JCheckBoxMenuItem 類別的可存取性支持。
 
從類別 javax.swing.JMenuItem 繼承的巢狀類別/介面
JMenuItem.AccessibleJMenuItem
 
從類別 javax.swing.AbstractButton 繼承的巢狀類別/介面
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
從類別 javax.swing.JComponent 繼承的巢狀類別/介面
JComponent.AccessibleJComponent
 
從類別 java.awt.Container 繼承的巢狀類別/介面
Container.AccessibleAWTContainer
 
從類別 java.awt.Component 繼承的巢狀類別/介面
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
欄位摘要
 
從類別 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
 
從類別 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
 
建構子摘要
JCheckBoxMenuItem()
          創建一個沒有設置文本或圖標的、最初未選定的複選框選單項。
JCheckBoxMenuItem(Action a)
          創建一個從所提供的 Action 中獲取其屬性的選單項。
JCheckBoxMenuItem(Icon icon)
          創建有一個帶圖標的、最初未被選定的複選框選單項。
JCheckBoxMenuItem(String text)
          創建一個帶文本的、最初未被選定的複選框選單項。
JCheckBoxMenuItem(String text, boolean b)
          創建帶有指定文本和選擇狀態的複選框選單項。
JCheckBoxMenuItem(String text, Icon icon)
          創建帶有指定文本和圖標的、最初未被選定的複選框選單項。
JCheckBoxMenuItem(String text, Icon icon, boolean b)
          創建帶有指定文本、圖標和選擇狀態的複選框選單項。
 
方法摘要
 AccessibleContext getAccessibleContext()
          獲得與此 JCheckBoxMenuItem 關聯的 AccessibleContext。
 Object[] getSelectedObjects()
          返回包含複選框選單項標籤的陣列 (length 1),如果沒有選定複選框,則返回 null。
 boolean getState()
          返回選單項的選定狀態。
 String getUIClassID()
          返回呈現此元件的 L&F 類別的名稱。
protected  String paramString()
          返回此 JCheckBoxMenuItem 的字元串表示形式。
 void setState(boolean b)
          設置該項的選定狀態。
 
從類別 javax.swing.JMenuItem 繼承的方法
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getComponent, getMenuDragMouseListeners, getMenuKeyListeners, getSubElements, init, isArmed, menuSelectionChanged, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setAccelerator, setArmed, setEnabled, setModel, setUI, updateUI
 
從類別 javax.swing.AbstractButton 繼承的方法
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, 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, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
從類別 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, 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
 
從類別 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, 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
 

建構子詳細資訊

JCheckBoxMenuItem

public JCheckBoxMenuItem()
創建一個沒有設置文本或圖標的、最初未選定的複選框選單項。


JCheckBoxMenuItem

public JCheckBoxMenuItem(Icon icon)
創建有一個帶圖標的、最初未被選定的複選框選單項。

參數:
icon - CheckBoxMenuItem 的圖標。

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text)
創建一個帶文本的、最初未被選定的複選框選單項。

參數:
text - CheckBoxMenuItem 的文本

JCheckBoxMenuItem

public JCheckBoxMenuItem(Action a)
創建一個從所提供的 Action 中獲取其屬性的選單項。

從以下版本開始:
1.3

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         Icon icon)
創建帶有指定文本和圖標的、最初未被選定的複選框選單項。

參數:
text - CheckBoxMenuItem 的文本
icon - CheckBoxMenuItem 的圖標

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         boolean b)
創建帶有指定文本和選擇狀態的複選框選單項。

參數:
text - 複選框選單項的文本
b - 複選框選單項的選定狀態

JCheckBoxMenuItem

public JCheckBoxMenuItem(String text,
                         Icon icon,
                         boolean b)
創建帶有指定文本、圖標和選擇狀態的複選框選單項。

參數:
text - 複選框選單項的文本
icon - 複選框選單項的圖標
b - 複選框選單項的選定狀態
方法詳細資訊

getUIClassID

public String getUIClassID()
返回呈現此元件的 L&F 類別的名稱。

覆寫:
類別 JMenuItem 中的 getUIClassID
返回:
"CheckBoxMenuItemUI"
另請參見:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

getState

public boolean getState()
返回選單項的選定狀態。此方法僅用於 AWT 相容性。新程式碼應該使用 isSelected() 。

返回:
如果該項被選定,則返回 true

setState

public void setState(boolean b)
設置該項的選定狀態。此方法僅用於 AWT 相容性。新程式碼應該使用 setSelected() 。

參數:
b - 指示該項選定狀態的 boolean 值,其中 true = 選定

getSelectedObjects

public Object[] getSelectedObjects()
返回包含複選框選單項標籤的陣列 (length 1),如果沒有選定複選框,則返回 null。

指定者:
介面 ItemSelectable 中的 getSelectedObjects
覆寫:
類別 AbstractButton 中的 getSelectedObjects
返回:
如果該項被選定,則返回包含一個 Object(選單項的文本)的陣列,否則返回 null

paramString

protected String paramString()
返回此 JCheckBoxMenuItem 的字元串表示形式。此方法僅在進行除錯時使用,對於各個實作,所返回字元串的內容和格式可能有所不同。返回的字元串可能為空,但不可能為 null

覆寫:
類別 JMenuItem 中的 paramString
返回:
此 JCheckBoxMenuItem 的字元串表示形式。

getAccessibleContext

public AccessibleContext getAccessibleContext()
獲得與此 JCheckBoxMenuItem 關聯的 AccessibleContext。對於 JCheckBoxMenuItems,AccessibleContext 採用 AccessibleJCheckBoxMenuItem 的形式。如有必要,可創建一個新的 AccessibleJCheckBoxMenuItem 實例。

指定者:
介面 Accessible 中的 getAccessibleContext
覆寫:
類別 JMenuItem 中的 getAccessibleContext
返回:
一個 AccessibleJCheckBoxMenuItem,它充當此 AccessibleJCheckBoxMenuItem 的 AccessibleContext

JavaTM 2 Platform
Standard Ed. 6

提交錯誤或意見

版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only