- 类型参数:
E- 此组合框元素的类型
- 所有已实现的接口:
ActionListener,ImageObserver,ItemSelectable,MenuContainer,Serializable,EventListener,Accessible,ListDataListener
Warning: Swing 不是线程安全的。有关详细信息,请参阅 Swing 的线程策略。
Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder 。
有关详细信息,请参阅 The Java Tutorial 中的 如何使用组合框。
- 自从:
- 1.2
- 参见:
-
内部类总结
内部类修饰符和类型类描述protected class此类实现了对JComboBox类的辅助功能支持。static interface定义KeySelectionManager的接口。在类 javax.swing.JComponent 中声明的嵌套类/接口
JComponent.AccessibleJComponent在类 java.awt.Container 中声明的嵌套类/接口
Container.AccessibleAWTContainer -
字段摘要
字段修饰符和类型Field描述protected String该受保护字段是特定于实现的。protected ComboBoxModel<E>该受保护字段是特定于实现的。protected ComboBoxEditor该受保护字段是特定于实现的。protected boolean该受保护字段是特定于实现的。protected JComboBox.KeySelectionManager该受保护字段是特定于实现的。protected boolean该受保护字段是特定于实现的。protected int该受保护字段是特定于实现的。protected ListCellRenderer<? super E>该受保护字段是特定于实现的。protected Object该受保护字段是特定于实现的。在类 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 -
构造方法总结
构造方法 -
方法总结
修饰符和类型方法描述void此方法作为实现副作用公开。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可编辑,则返回真。boolean获取lightWeightPopupEnabled属性的值。boolean确定弹出窗口的可见性。protected String返回此JComboBox的字符串表示形式void处理KeyEvents,寻找 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 属性重置为当前外观的值。在类 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, update在类 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, 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
-
字段详细信息
-
dataModel
该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
renderer
该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
editor
该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
maximumRowCount
protected int maximumRowCount该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
isEditable
protected boolean isEditable该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
keySelectionManager
该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
actionCommand
该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
lightWeightPopupEnabled
protected boolean lightWeightPopupEnabled该受保护字段是特定于实现的。不要直接访问或重写。请改用访问器方法。- 参见:
-
selectedItemReminder
该受保护字段是特定于实现的。不要直接访问或重写。
-
-
构造方法详细信息
-
JComboBox
创建一个JComboBox,它从现有的ComboBoxModel中获取其项目。由于提供了ComboBoxModel,使用此构造函数创建的组合框不会创建默认组合框模型,并且可能会影响插入、删除和添加方法的行为方式。- 参数:
aModel- 提供显示的项目列表的ComboBoxModel- 参见:
-
JComboBox
创建一个包含指定数组中的元素的JComboBox。默认情况下,数组中的第一项(以及数据模型)被选中。- 参数:
items- 要插入组合框的对象数组- 参见:
-
JComboBox
创建一个包含指定 Vector 中的元素的JComboBox。默认情况下,向量中的第一项(以及数据模型)被选中。- 参数:
items- 要插入组合框的向量数组- 参见:
-
JComboBox
public JComboBox()使用默认数据模型创建JComboBox。默认数据模型是一个空的对象列表。使用addItem添加项目。默认情况下,数据模型中的第一项被选中。- 参见:
-
-
方法详情
-
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- 一个boolean,其中 true 表示该字段是可编辑的
-
isEditable
public boolean isEditable()如果JComboBox可编辑,则返回真。默认情况下,组合框是不可编辑的。- 返回:
-
如果
JComboBox是可编辑的,则为真,否则为假
-
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是not在列表中并且组合框是不可编辑的,它不会改变当前的选择。对于可编辑的组合框,选择将更改为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使用可变数据模型时有效。Warning: 如果添加重复的 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- 一个 int,指定要删除的项目的索引,其中 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
返回使用 addItemListener() 添加到此 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
设置应包含在发送给动作监听的事件中的动作命令。- 参数:
aCommand- 包含发送给动作监听器的“命令”的字符串;同一个监听器可以根据收到的命令做不同的事情
-
getActionCommand
返回发送给动作监听的事件中包含的动作命令。- 返回:
- 包含发送给动作监听的“命令”的字符串。
-
setAction
@BeanProperty (visualUpdate =true, description ="the Action instance connected with this ActionEvent source") public void setAction(Action a) 为ActionEvent源设置Action。新的Action取代了之前设置的任何Action但不影响ActionListeners独立添加addActionListener。如果Action已经是ActionEvent源的已注册ActionListener,则不会重新注册。设置
Action会导致立即更改 摇摆组件支持Action中描述的所有属性。随后,组合框的属性会随着Action的属性更改而自动更新。此方法使用其他三种方法来设置和帮助跟踪
Action的属性值。它使用configurePropertiesFromAction方法立即更改组合框的属性。为了跟踪Action的属性值的变化,此方法注册了createActionPropertyChangeListener返回的PropertyChangeListener。当Action中的属性更改时,默认PropertyChangeListener调用actionPropertyChanged方法。- 参数:
a-JComboBox的Action或null。- 自从:
- 1.3
- 参见:
-
getAction
返回当前为此ActionEvent源设置的Action,如果未设置Action,则返回null。- 返回:
-
这个
ActionEvent来源的Action;或者null - 自从:
- 1.3
- 参见:
-
configurePropertiesFromAction
设置此组合框的属性以匹配指定的Action中的属性。有关此设置的属性的更多详细信息,请参阅 摇摆组件支持Action。- 参数:
a- 从中获取属性的Action,或null- 自从:
- 1.3
- 参见:
-
createActionPropertyChangeListener
创建并返回一个PropertyChangeListener负责监听来自指定Action的更改并更新相应的属性。警告:如果您将其子类化,则不要创建匿名内部类。如果你这样做,组合框的生命周期将与
Action的生命周期相关联。- 参数:
a- 组合框的动作- 返回:
PropertyChangeListener- 自从:
- 1.3
- 参见:
-
actionPropertyChanged
更新组合框的状态以响应关联操作中的属性更改。从createActionPropertyChangeListener返回的PropertyChangeListener调用此方法。子类通常不需要调用它。支持额外Action属性的子类应该覆盖这个和configurePropertiesFromAction。有关此方法设置的属性列表,请参阅 摇摆组件支持
Action中的表格。- 参数:
action- 与此组合框关联的ActionpropertyName- 更改的属性的名称- 自从:
- 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。否则,返回假。- 参数:
keyChar- 一个字符,通常这是用户键入的键盘键- 返回:
true是否有与该字符对应的项目。否则,返回false。
-
setEnabled
@BeanProperty (preferred =true, description ="The enabled state of the component.") public void setEnabled(boolean b) 启用组合框以便可以选择项目。当组合框被禁用时,无法选择项目并且无法在其字段中键入值(如果它是可编辑的)。- 重写:
setEnabled在类JComponent中- 参数:
b- 一个boolean,其中 true 启用组件,false 禁用它- 参见:
-
configureEditor
使用指定项初始化编辑器。- 参数:
anEditor- 在组合框字段中显示列表项并允许编辑的ComboBoxEditoranItem- 在字段中显示和编辑的对象
-
processKeyEvent
处理KeyEvents,寻找 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
-