- 类型参数:
-
E- 此组合框元素的类型
- 所有实现的接口:
-
ActionListener,ImageObserver,ItemSelectable,MenuContainer,Serializable,EventListener,Accessible,ListDataListener
警告: Swing 不是线程安全的。更多信息请参阅 Swing的线程策略。
警告: 此类的序列化对象将不兼容未来的 Swing 版本。当前的序列化支持适用于短期存储或在运行相同 Swing 版本的应用程序之间的 RMI。从 1.4 版开始,已将所有 JavaBeans 的长期存储支持添加到 java.beans 包中。请参阅 XMLEncoder。
请参阅 如何使用组合框 在 The Java Tutorial 中获取更多信息。
- 自 JDK 版本:
- 1.2
- 另请参见:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class此类为JComboBox类实现了辅助功能支持。static interface定义了一个KeySelectionManager的接口。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
FieldsModifier and TypeFieldDescriptionprotected String此受保护字段是特定于实现的。protected ComboBoxModel<E> 此受保护字段是特定于实现的。protected ComboBoxEditor此受保护字段是特定于实现的。protected boolean此受保护字段是特定于实现的。protected JComboBox.KeySelectionManager此受保护字段是特定于实现的。protected boolean此受保护字段是特定于实现的。protected int此受保护字段是特定于实现的。protected ListCellRenderer<? super E> 此受保护字段是特定于实现的。protected Object此受保护字段是特定于实现的。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, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid此方法作为实现的副作用是公共的。protected voidactionPropertyChanged(Action action, String propertyName) 根据关联操作中的属性更改更新组合框的状态。void添加一个ActionListener。void向项目列表添加一个项目。voidaddItemListener(ItemListener aListener) 添加一个ItemListener。void添加一个PopupMenu监听器,该监听器将监听来自组合框弹出部分的通知消息。voidconfigureEditor(ComboBoxEditor anEditor, Object anItem) 使用指定项目初始化编辑器。protected void将此组合框的属性设置为与指定Action中的属性相匹配。void此方法作为实现的副作用是公共的。protected PropertyChangeListener创建并返回一个PropertyChangeListener,负责监听来自指定Action的更改并更新相应的属性。protected JComboBox.KeySelectionManager返回默认键选择管理器的实例。protected void通知所有已注册对此事件类型感兴趣的监听器。protected void通知所有已注册对此事件类型感兴趣的监听器。void通知PopupMenuListener,组合框的弹出部分已被取消。void通知PopupMenuListener,组合框的弹出部分已变为不可见。void通知PopupMenuListener,组合框的弹出部分将变为可见。获取与此 JComboBox 关联的 AccessibleContext。返回此ActionEvent源当前设置的Action,如果未设置Action,则返回null。返回发送给操作监听器的事件中包含的操作命令。返回使用 addActionListener() 添加到此 JComboBox 的所有ActionListener的数组。返回用于在JComboBox字段中绘制和编辑所选项目的编辑器。getItemAt(int index) 返回指定索引处的列表项。int返回列表中的项目数。返回使用 addItemListener() 添加到此 JComboBox 的所有ItemListener的数组。返回列表的键选择管理器。int返回组合框在没有滚动条的情况下可以显示的最大项目数。getModel()返回当前由JComboBox使用的数据模型。返回使用 addPopupMenuListener() 添加到此 JComboBox 的所有PopupMenuListener的数组。返回“原型显示”值 - 用于计算显示高度和宽度的对象。ListCellRenderer<? super E> 返回用于在JComboBox字段中显示所选项目的渲染器。int返回列表中与给定项目匹配的第一个项目。返回当前选定的项目。Object[]返回包含所选项目的数组。getUI()返回呈现此组件的 L&F 对象。返回呈现此组件的 L&F 类的名称。void使组合框关闭其弹出窗口。voidinsertItemAt(E item, int index) 在给定索引处向项目列表插入项目。protected void注册祖先监听器,以便在其自身或任何祖先移动或变为可见或不可见时接收AncestorEvents。void此方法作为实现的副作用是公共的。void此方法作为实现的副作用是公共的。boolean如果JComboBox可编辑,则返回 true。boolean获取lightWeightPopupEnabled属性的值。boolean确定弹出窗口的可见性。protected String返回此JComboBox的字符串表示形式。void处理KeyEvent,查找 Tab 键。void移除一个ActionListener。void从项目列表中移除所有项目。voidremoveItem(Object anObject) 从项目列表中移除一个项目。voidremoveItemAt(int anIndex) 移除anIndex处的项目。仅当JComboBox使用可变数据模型时才有效。voidremoveItemListener(ItemListener aListener) 移除一个ItemListener。void移除一个PopupMenuListener。protected void此受保护方法是特定于实现的。booleanselectWithKeyChar(char keyChar) 选择与指定键盘字符对应的列表项,并返回 true,如果有与该字符对应的项目。void为ActionEvent源设置Action。voidsetActionCommand(String aCommand) 设置应包含在发送给操作监听器的事件中的操作命令。voidsetEditable(boolean aFlag) 确定JComboBox字段是否可编辑。voidsetEditor(ComboBoxEditor anEditor) 设置用于在JComboBox字段中绘制和编辑所选项目的编辑器。voidsetEnabled(boolean b) 启用组合框,以便可以选择项目。void设置将键盘字符转换为列表选择的对象。voidsetLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性,该属性提供提示,指示是否应使用轻量级Component来包含JComboBox,而不是重量级Component,如Panel或Window。voidsetMaximumRowCount(int count) 设置JComboBox显示的最大行数。voidsetModel(ComboBoxModel<E> aModel) 设置JComboBox使用的数据模型以获取项目列表。voidsetPopupVisible(boolean v) 设置弹出窗口的可见性。voidsetPrototypeDisplayValue(E prototypeDisplayValue) 设置用于计算 UI 部分显示大小的原型显示值。voidsetRenderer(ListCellRenderer<? super E> aRenderer) 设置用于在JComboBox字段中显示列表项和所选列表项的渲染器。voidsetSelectedIndex(int anIndex) 选择索引为anIndex处的项目。voidsetSelectedItem(Object anObject) 将组合框显示区域中当前选定的项目设置为参数中的对象。voidsetUI(ComboBoxUI ui) 设置呈现此组件的 L&F 对象。void使组合框显示其弹出窗口。voidupdateUI()将 UI 属性重置为当前外观和感觉的值。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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, 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, addImpl, 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
-
Field Details
-
dataModel
此受保护字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 另请参见:
-
renderer
这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
editor
这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
maximumRowCount
protected int maximumRowCount这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
isEditable
protected boolean isEditable这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
keySelectionManager
这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
actionCommand
这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
lightWeightPopupEnabled
protected boolean lightWeightPopupEnabled这个受保护的字段是特定于实现的。请勿直接访问或覆盖。请改用访问器方法。- 参见:
-
selectedItemReminder
这个受保护的字段是特定于实现的。请勿直接访问或覆盖。
-
-
Constructor Details
-
JComboBox
创建一个从现有ComboBoxModel获取项目的JComboBox。由于提供了ComboBoxModel,使用此构造函数创建的组合框不会创建默认的组合框模型,并且可能影响插入、删除和添加方法的行为。- 参数:
-
aModel- 提供显示的项目列表的ComboBoxModel - 参见:
-
JComboBox
创建一个包含指定数组中元素的JComboBox。默认情况下,数组中的第一个项目(因此数据模型)将被选中。- 参数:
-
items- 要插入到组合框中的对象数组 - 参见:
-
JComboBox
创建一个包含指定Vector中元素的JComboBox。默认情况下,向量中的第一个项目(因此数据模型)将被选中。- 参数:
-
items- 要插入到组合框中的向量数组 - 参见:
-
JComboBox
public JComboBox()创建一个带有默认数据模型的JComboBox。默认数据模型是一个空对象列表。使用addItem添加项目。默认情况下,数据模型中的第一个项目将被选中。- 参见:
-
-
Method Details
-
installAncestorListener
protected void installAncestorListener()注册祖先侦听器,以便在它或其任何祖先移动或变为可见或不可见时接收AncestorEvents。当组件或其祖先添加或从包含层次结构中移除时,也会发送事件。 -
setUI
@BeanProperty(hidden=true, visualUpdate=true, description="The UI object that implements the Component\'s LookAndFeel.") public void setUI(ComboBoxUI ui) 设置呈现此组件的L&F对象。- 参数:
-
ui-ComboBoxUIL&F对象 - 参见:
-
updateUI
public void updateUI()将UI属性重置为当前外观的值。- 覆盖:
-
updateUI在类JComponent - 参见:
-
getUIClassID
返回呈现此组件的L&F类的名称。- 覆盖:
-
getUIClassID在类JComponent - 返回:
- 字符串"ComboBoxUI"
- 参见:
-
getUI
返回呈现此组件的L&F对象。- 覆盖:
-
getUI在类JComponent - 返回:
- 渲染此组件的ComboBoxUI对象
-
setModel
@BeanProperty(description="Model that the combo box uses to get data to display.") public void setModel(ComboBoxModel<E> aModel) 设置JComboBox使用的数据模型以获取项目列表。- 参数:
-
aModel- 提供显示的项目列表的ComboBoxModel
-
getModel
返回JComboBox当前使用的数据模型。- 返回:
-
提供显示的项目列表的
ComboBoxModel
-
setLightWeightPopupEnabled
@BeanProperty(expert=true, description="Set to <code>false</code> to require heavyweight popups.") public void setLightWeightPopupEnabled(boolean aFlag) 设置lightWeightPopupEnabled属性,该属性提供关于是否应使用轻量级Component来包含JComboBox的提示,而不是使用重量级Component,如Panel或Window。轻量级与重量级的决定最终由JComboBox决定。轻量级窗口比重量级窗口更高效,但轻量级和重量级组件在GUI中不搭配。如果您的应用程序混合使用轻量级和重量级组件,则应禁用轻量级弹出窗口。默认情况下,lightWeightPopupEnabled属性的值为true,除非外观和感觉另有规定。一些外观和感觉始终使用重量级弹出窗口,无论此属性的值如何。请参阅文章混合重量和轻量组件此方法会触发属性更改事件。
- 参数:
-
aFlag- 如果为true,则希望使用轻量级弹出窗口
-
isLightWeightPopupEnabled
public boolean isLightWeightPopupEnabled()获取lightWeightPopupEnabled属性的值。- 返回:
-
lightWeightPopupEnabled属性的值 - 参见:
-
setEditable
@BeanProperty(preferred=true, description="If true, the user can type a new value in the combo box.") public void setEditable(boolean aFlag) 确定JComboBox字段是否可编辑。可编辑的JComboBox允许用户在字段中键入或从列表中选择项目以初始化字段,之后可以编辑字段。(编辑仅影响字段,列表项保持不变。)不可编辑的JComboBox在字段中显示所选项目,但选择无法修改。- 参数:
-
aFlag- 一个布尔值,其中true表示字段是可编辑的
-
isEditable
public boolean isEditable()如果JComboBox可编辑,则返回true。默认情况下,组合框不可编辑。- 返回:
-
如果
JComboBox可编辑,则为true,否则为false
-
setMaximumRowCount
@BeanProperty(preferred=true, description="The maximum number of rows the popup should have") public void setMaximumRowCount(int count) 设置JComboBox显示的最大行数。如果模型中的对象数大于计数,则组合框使用滚动条。- 参数:
-
count- 指定在使用滚动条之前在列表中显示的最大项目数的整数
-
getMaximumRowCount
public int getMaximumRowCount()返回组合框在不使用滚动条的情况下可以显示的最大项目数- 返回:
- 指定在使用滚动条之前在列表中显示的最大项目数的整数
-
setRenderer
@BeanProperty(expert=true, description="The renderer that paints the item selected in the list.") public void setRenderer(ListCellRenderer<? super E> aRenderer) 设置绘制列表项和从列表中选择的项目的JComboBox字段的渲染器。如果JComboBox不可编辑,则使用渲染器。如果可编辑,则使用编辑器来渲染和编辑所选项目。默认渲染器显示字符串或图标。其他渲染器可以处理图形图像和复合项目。
要显示所选项目,将调用
aRenderer.getListCellRendererComponent,传递列表对象和索引-1。- 参数:
-
aRenderer- 显示所选项目的ListCellRenderer - 参见:
-
getRenderer
返回用于在JComboBox字段中显示所选项目的渲染器。- 返回:
-
显示所选项目的
ListCellRenderer
-
setEditor
@BeanProperty(expert=true, description="The editor that combo box uses to edit the current value") public void setEditor(ComboBoxEditor anEditor) 设置用于在JComboBox字段中绘制和编辑所选项目的编辑器。仅当接收的JComboBox可编辑时才使用编辑器。如果不可编辑,则组合框使用渲染器来绘制所选项目。- 参数:
-
anEditor- 显示所选项目的ComboBoxEditor - 参见:
-
getEditor
返回用于在JComboBox字段中绘制和编辑所选项目的编辑器。- 返回:
-
显示所选项目的
ComboBoxEditor
-
setSelectedItem
@BeanProperty(bound=false, preferred=true, description="Sets the selected item in the JComboBox.") public void setSelectedItem(Object anObject) 将组合框显示区域中的选定项目设置为参数中的对象。如果anObject在列表中,则显示区域显示所选的anObject。如果
anObject不在列表中且组合框不可编辑,则不会更改当前选择。对于可编辑的组合框,选择将更改为anObject。如果这构成所选项目的更改,则添加到组合框的
ItemListener将收到一个或两个ItemEvent通知。如果有当前选定的项目,则将触发一个ItemEvent,状态更改为ItemEvent.DESELECTED。如果anObject在列表中且当前未选定,则将触发一个ItemEvent,状态更改为ItemEvent.SELECTED。调用此方法时,添加到组合框的
ActionListener将收到一个ActionEvent。- 参数:
-
anObject- 要选择的列表对象;使用null来清除选择
-
getSelectedItem
返回当前选定的项目。如果组合框可编辑,则此值可能未使用
addItem、insertItemAt或数据构造函数将其添加到组合框中。- 返回:
- 当前选定的对象
- 参见:
-
setSelectedIndex
@BeanProperty(bound=false, preferred=true, description="The item at index is selected.") public void setSelectedIndex(int anIndex) 选择索引为anIndex的项目。- 参数:
-
anIndex- 指定要选择的列表项的整数,其中0指定列表中的第一项,-1表示无选择 - 抛出:
-
IllegalArgumentException- 如果anIndex< -1或anIndex大于或等于大小
-
getSelectedIndex
public int getSelectedIndex()返回与给定项目匹配的列表中的第一个项目。如果JComboBox允许选择不在列表中的项目,则结果并非总是定义的。如果没有选定项目或用户指定的项目不在列表中,则返回-1。- 返回:
- 指定当前选定列表项的整数,其中0指定列表中的第一项;如果未选择任何项目或当前选定项目不在列表中,则返回-1
-
getPrototypeDisplayValue
返回“原型显示”值 - 用于计算显示高度和宽度的对象。- 返回:
-
prototypeDisplayValue属性的值 - 自:
- 1.4
- 参见:
-
setPrototypeDisplayValue
@BeanProperty(visualUpdate=true, description="The display prototype value, used to compute display width and height.") public void setPrototypeDisplayValue(E prototypeDisplayValue) 设置用于计算UI部分显示大小的原型显示值。如果指定了原型显示值,则通过配置渲染器使用原型显示值计算组合框的首选大小。在组合框将显示大量数据时,指定首选显示值通常很有用。如果未指定原型显示值,则必须为模型中的每个值配置渲染器并获取其首选大小,这可能相对昂贵。
- 参数:
-
prototypeDisplayValue- 原型显示值 - 自:
- 1.4
- 参见:
-
addItem
向项目列表添加一个项目。此方法仅在JComboBox使用可变数据模型时有效。警告: 如果添加重复的String对象,可能会出现焦点和键盘导航问题。一种解决方法是添加新对象而不是String对象,并确保定义了toString()方法。例如:
comboBox.addItem(makeObj("Item 1")); comboBox.addItem(makeObj("Item 1")); ... private Object makeObj(final String item) { return new Object() { public String toString() { return item; } }; }- 参数:
-
item- 要添加到列表中的项目 - 参见:
-
insertItemAt
在给定索引处向项目列表中插入一个项目。此方法仅在JComboBox使用可变数据模型时有效。- 参数:
-
item- 要添加到列表中的项目 -
index- 指定要添加项目的位置的整数 - 参见:
-
removeItem
从项目列表中删除一个项目。此方法仅在JComboBox使用可变数据模型时有效。- 参数:
-
anObject- 要从项目列表中删除的对象 - 参见:
-
removeItemAt
public void removeItemAt(int anIndex) 删除索引为anIndex的项目。此方法仅在JComboBox使用可变数据模型时有效。- 参数:
-
anIndex- 指定要删除项目的索引的整数,其中0表示列表中的第一个项目 - 参见:
-
removeAllItems
public void removeAllItems()删除项目列表中的所有项目。 -
showPopup
public void showPopup()使组合框显示其弹出窗口。- 参见:
-
hidePopup
public void hidePopup()使组合框关闭其弹出窗口。- 参见:
-
setPopupVisible
public void setPopupVisible(boolean v) 设置弹出窗口的可见性。- 参数:
-
v- 如果为true,则显示弹出窗口,否则隐藏弹出窗口。
-
isPopupVisible
public boolean isPopupVisible()确定弹出窗口的可见性。- 返回:
- 如果弹出窗口可见,则返回true,否则返回false
-
addItemListener
添加一个ItemListener。当选定项目更改时,
aListener将接收一个或两个ItemEvent。- 指定者:
-
addItemListener在接口ItemSelectable中 - 参数:
-
aListener- 要通知的ItemListener - 参见:
-
removeItemListener
删除一个ItemListener。- 指定者:
-
removeItemListener在接口ItemSelectable中 - 参数:
-
aListener- 要移除的ItemListener - 参见:
-
getItemListeners
返回添加到此JComboBox的所有ItemListener的数组。- 返回:
-
所有已添加的
ItemListener数组,如果未添加任何侦听器,则返回空数组 - 自:
- 1.4
-
addActionListener
添加一个ActionListener。当进行选择时,
ActionListener将接收一个ActionEvent。如果组合框可编辑,则在编辑完成时将触发ActionEvent。- 参数:
-
l- 要通知的ActionListener - 参见:
-
removeActionListener
删除一个ActionListener。- 参数:
-
l- 要移除的ActionListener
-
getActionListeners
返回一个数组,其中包含通过addActionListener()添加到此JComboBox的所有ActionListener。- 返回:
- 所有已添加的ActionListener,如果未添加任何监听器,则返回空数组
- 自:
- 1.4
-
addPopupMenuListener
添加一个PopupMenu监听器,用于监听来自组合框弹出部分的通知消息。对于Java附带的所有标准外观和感觉,组合框的弹出列表部分是作为JPopupMenu实现的。自定义外观和感觉可能不是这样实现的,因此将无法接收到通知。
- 参数:
- l - 要添加的PopupMenuListener
- 自:
- 1.4
-
removePopupMenuListener
移除一个PopupMenuListener。- 参数:
- l - 要移除的PopupMenuListener
- 自:
- 1.4
- 另请参阅:
-
getPopupMenuListeners
返回一个数组,其中包含通过addPopupMenuListener()添加到此JComboBox的所有PopupMenuListener。- 返回:
- 所有已添加的PopupMenuListener,如果未添加任何监听器,则返回空数组
- 自:
- 1.4
-
firePopupMenuWillBecomeVisible
public void firePopupMenuWillBecomeVisible()通知PopupMenuListener,组合框的弹出部分将变为可见。此方法是公共的,但除了UI代理之外不应由任何其他对象调用。
- 自:
- 1.4
- 另请参阅:
-
firePopupMenuWillBecomeInvisible
public void firePopupMenuWillBecomeInvisible()通知PopupMenuListener,组合框的弹出部分已变为不可见。此方法是公共的,但除了UI代理之外不应由任何其他对象调用。
- 自:
- 1.4
- 另请参阅:
-
firePopupMenuCanceled
public void firePopupMenuCanceled()通知PopupMenuListener,组合框的弹出部分已被取消。此方法是公共的,但除了UI代理之外不应由任何其他对象调用。
- 自:
- 1.4
- 另请参阅:
-
setActionCommand
设置应包含在发送给action监听器的事件中的操作命令。- 参数:
- aCommand - 包含发送给action监听器的“命令”的字符串;然后,相同的监听器可以根据接收到的命令执行不同的操作
-
getActionCommand
返回包含发送给action监听器的事件中的操作命令的字符串。- 返回:
- 包含发送给action监听器的“命令”的字符串。
-
setAction
@BeanProperty(visualUpdate=true, description="the Action instance connected with this ActionEvent source") public void setAction(Action a) 为ActionEvent源设置Action。新的Action将替换先前设置的任何Action,但不会影响独立使用addActionListener添加的ActionListeners。如果Action已经是ActionEvent源的注册ActionListener,则不会重新注册。设置Action会立即更改所有在支持Action的Swing组件中描述的属性。随后,随着Action的属性更改,组合框的属性会自动更新。
此方法使用其他三个方法来设置和帮助跟踪Action的属性值。它使用configurePropertiesFromAction方法立即更改组合框的属性。为了跟踪Action的属性值的更改,此方法注册createActionPropertyChangeListener返回的PropertyChangeListener。默认的PropertyChangeListener在Action的属性更改时调用actionPropertyChanged方法。
- 参数:
- a - JComboBox的Action,或null。
- 自:
- 1.3
- 另请参阅:
-
getAction
返回为此ActionEvent源设置的当前Action,如果未设置Action,则返回null。- 返回:
- 此ActionEvent源的Action;或null
- 自:
- 1.3
- 另请参阅:
-
configurePropertiesFromAction
设置此组合框上的属性以匹配指定Action中的属性。有关设置的属性,请参阅支持Action的Swing组件以获取更多详细信息。- 参数:
- a - 从中获取属性的Action,或null
- 自:
- 1.3
- 另请参阅:
-
createActionPropertyChangeListener
创建并返回一个负责监听指定Action的更改并更新相应属性的PropertyChangeListener。警告:如果您对此进行子类化,请勿创建匿名内部类。如果这样做,组合框的生命周期将与Action的生命周期绑定。
- 参数:
- a - 组合框的Action
- 返回:
- PropertyChangeListener
- 自:
- 1.3
- 另请参阅:
-
actionPropertyChanged
根据关联Action中的属性更改更新组合框的状态。此方法是从createActionPropertyChangeListener返回的PropertyChangeListener调用的。通常情况下,子类不需要调用此方法。支持其他Action属性的子类应该重写此方法和configurePropertiesFromAction。请参阅支持Action的Swing组件表格,了解此方法设置的属性列表。
- 参数:
- action - 与此组合框关联的Action
- propertyName - 更改的属性的名称
- 自:
- 1.6
- 另请参阅:
-
fireItemStateChanged
通知所有已注册对此事件类型的通知感兴趣的监听器。- 参数:
- e - 感兴趣的事件
- 另请参阅:
-
fireActionEvent
protected void fireActionEvent()通知所有已注册对此事件类型的通知感兴趣的监听器。- 另请参阅:
-
selectedItemChanged
protected void selectedItemChanged()此受保护的方法是特定于实现的。请勿直接访问或覆盖。 -
getSelectedObjects
返回包含所选项目的数组。此方法是为了与ItemSelectable兼容而实现的。- 指定者:
-
getSelectedObjects在接口ItemSelectable中 - 返回:
- 包含一个元素(所选项目)的Objects数组
-
actionPerformed
此方法是公共的,作为实现副作用。请勿调用或覆盖。- 指定者:
-
actionPerformed在接口ActionListener中 - 参数:
- e - 要处理的事件
-
contentsChanged
此方法是公共的,作为实现副作用。请勿调用或覆盖。- 指定者:
-
contentsChanged在接口ListDataListener中 - 参数:
-
e- 封装事件信息的ListDataEvent
-
intervalAdded
此方法作为实现的副作用而公开。请勿调用或覆盖。- 指定者:
-
intervalAdded在接口ListDataListener中 - 参数:
-
e- 封装事件信息的ListDataEvent
-
intervalRemoved
此方法作为实现的副作用而公开。请勿调用或覆盖。- 指定者:
-
intervalRemoved在接口ListDataListener中 - 参数:
-
e- 封装事件信息的ListDataEvent
-
selectWithKeyChar
public boolean selectWithKeyChar(char keyChar) 选择与指定键盘字符对应的列表项,并返回true,如果有与该字符对应的项目。否则,返回false。- 参数:
-
keyChar- 一个字符,通常是用户键入的键盘键 - 返回:
-
如果有与该字符对应的项目,则返回
true。否则,返回false。
-
setEnabled
@BeanProperty(preferred=true, description="The enabled state of the component.") public void setEnabled(boolean b) 启用组合框,以便可以选择项目。当组合框被禁用时,无法选择项目,也无法在其字段中键入值(如果可编辑)。- 覆盖:
-
setEnabled在类JComponent中 - 参数:
-
b- 一个布尔值,其中true启用组件,false禁用组件 - 参见:
-
configureEditor
使用指定项目初始化编辑器。- 参数:
-
anEditor- 在组合框字段中显示列表项并允许编辑的ComboBoxEditor -
anItem- 要在字段中显示和编辑的对象
-
processKeyEvent
处理KeyEvent,查找Tab键。如果找到Tab键,则关闭弹出窗口。- 覆盖:
-
processKeyEvent在类JComponent中 - 参数:
-
e- 包含按下的键盘键的KeyEvent - 参见:
-
setKeySelectionManager
@BeanProperty(bound=false, expert=true, description="The objects that changes the selection when a key is pressed.") public void setKeySelectionManager(JComboBox.KeySelectionManager aManager) 设置将键盘字符转换为列表选择的对象。通常,具有匹配的第一个字符的第一个选择项将成为所选项目。- 参数:
-
aManager- 一个键选择管理器
-
getKeySelectionManager
返回列表的键选择管理器。- 返回:
-
当前使用的
KeySelectionManager
-
getItemCount
返回列表中的项目数。- 返回:
- 与列表中项目数相等的整数
-
getItemAt
返回指定索引处的列表项。如果index超出范围(小于零或大于等于大小),它将返回null。- 参数:
-
index- 指示列表位置的整数,其中第一个项目从零开始 - 返回:
-
该列表位置处的项目;如果超出范围,则返回
null
-
createDefaultKeySelectionManager
返回默认键选择管理器的实例。- 返回:
-
当前由列表使用的
KeySelectionManager - 参见:
-
paramString
返回此JComboBox的字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能因实现而异。返回的字符串可能为空,但不能为null。- 覆盖:
-
paramString在类JComponent中 - 返回:
-
此
JComboBox的字符串表示形式
-
getAccessibleContext
获取与此JComboBox关联的AccessibleContext。对于组合框,AccessibleContext采用AccessibleJComboBox的形式。如果需要,将创建一个新的AccessibleJComboBox实例。- 指定者:
-
getAccessibleContext在接口Accessible中 - 覆盖:
-
getAccessibleContext在类Component中 - 返回:
- 作为此JComboBox的AccessibleContext的AccessibleJComboBox
-