E - 这个组合框的元素的类型
public class JComboBox<E> extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible
警告: Swing不是线程安全的。 有关更多信息,请参阅Swing's Threading Policy 。
警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。
ComboBoxModel , DefaultComboBoxModel
| Modifier and Type | Class and Description |
|---|---|
protected class |
JComboBox.AccessibleJComboBox
这个类实现了可访问性支持
JComboBox类。
|
static interface |
JComboBox.KeySelectionManager
界面定义了一个
KeySelectionManager 。
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
protected String |
actionCommand
此保护字段是实现特定的。
|
protected ComboBoxModel<E> |
dataModel
此保护字段是实现特定的。
|
protected ComboBoxEditor |
editor
此保护字段是实现特定的。
|
protected boolean |
isEditable
此保护字段是实现特定的。
|
protected JComboBox.KeySelectionManager |
keySelectionManager
此保护字段是实现特定的。
|
protected boolean |
lightWeightPopupEnabled
此保护字段是实现特定的。
|
protected int |
maximumRowCount
此保护字段是实现特定的。
|
protected ListCellRenderer<? super E> |
renderer
此保护字段是实现特定的。
|
protected Object |
selectedItemReminder
此保护字段是实现特定的。
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JComboBox()
使用默认数据模型创建
JComboBox 。
|
JComboBox(ComboBoxModel<E> aModel)
创建一个
JComboBox ,从现有的
ComboBoxModel获取其项目。
|
JComboBox(E[] items)
创建
JComboBox包含指定数组中的元素。
|
JComboBox(Vector<E> items)
创建一个
JComboBox包含指定Vector中的元素。
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(ActionEvent e)
这种方法是公共的,作为实现的副作用。
|
protected void |
actionPropertyChanged(Action action, String propertyName)
响应关联操作中的属性更改更新组合框的状态。
|
void |
addActionListener(ActionListener l)
添加一个
ActionListener 。
|
void |
addItem(E item)
将项目添加到项目列表。
|
void |
addItemListener(ItemListener aListener)
添加一个
ItemListener 。
|
void |
addPopupMenuListener(PopupMenuListener l)
添加一个
PopupMenu监听器,它将从组合框的弹出窗口中收听通知消息。
|
void |
configureEditor(ComboBoxEditor anEditor, Object anItem)
用指定的项目初始化编辑器。
|
protected void |
configurePropertiesFromAction(Action a)
设置此组合框上的属性,以匹配指定的Action中的
Action 。
|
void |
contentsChanged(ListDataEvent e)
这种方法是公共的,作为实现的副作用。
|
protected PropertyChangeListener |
createActionPropertyChangeListener(Action a)
创建并返回一个
PropertyChangeListener ,负责监听来自指定的变化
Action和更新相应的属性。
|
protected JComboBox.KeySelectionManager |
createDefaultKeySelectionManager()
返回默认密钥选择管理器的一个实例。
|
protected void |
fireActionEvent()
通知所有在此事件类型上通知有兴趣的听众。
|
protected void |
fireItemStateChanged(ItemEvent e)
通知所有在此事件类型上通知有兴趣的听众。
|
void |
firePopupMenuCanceled()
通知
PopupMenuListener s组合框的弹出部分已被取消。
|
void |
firePopupMenuWillBecomeInvisible()
通知
PopupMenuListener s组合框的弹出部分已经变得不可见。
|
void |
firePopupMenuWillBecomeVisible()
通知
PopupMenuListener s组合框的弹出部分将变得可见。
|
AccessibleContext |
getAccessibleContext()
获取与此JComboBox关联的AccessibleContext。
|
Action |
getAction()
返回当前设置
Action这个
ActionEvent来源,或
null如果没有
Action设置。
|
String |
getActionCommand()
返回发送到动作侦听器的事件中包含的动作命令。
|
ActionListener[] |
getActionListeners()
返回使用addActionListener()添加到此JComboBox的所有
ActionListener的数组。
|
ComboBoxEditor |
getEditor()
返回在
JComboBox字段中用于绘制和编辑所选项目的编辑器。
|
E |
getItemAt(int index)
返回指定索引处的列表项。
|
int |
getItemCount()
返回列表中的项目数。
|
ItemListener[] |
getItemListeners()
返回使用addItemListener()添加到此JComboBox的所有
ItemListener的数组。
|
JComboBox.KeySelectionManager |
getKeySelectionManager()
返回列表的密钥选择管理器。
|
int |
getMaximumRowCount()
返回在没有滚动条的情况下组合框可以显示的最大项数
|
ComboBoxModel<E> |
getModel()
返回当前使用的数据模型
JComboBox 。
|
PopupMenuListener[] |
getPopupMenuListeners()
返回使用addPopupMenuListener()添加到此JComboBox的所有
PopupMenuListener的数组。
|
E |
getPrototypeDisplayValue()
返回“原型显示”值 - 用于计算显示高度和宽度的对象。
|
ListCellRenderer<? super E> |
getRenderer()
返回用于在
JComboBox字段中显示所选项目的渲染器。
|
int |
getSelectedIndex()
返回列表中与给定项目匹配的第一个项目。
|
Object |
getSelectedItem()
返回当前所选项目。
|
Object[] |
getSelectedObjects()
返回一个包含所选项目的数组。
|
ComboBoxUI |
getUI()
返回渲染此组件的L&F对象。
|
String |
getUIClassID()
返回呈现此组件的L&F类的名称。
|
void |
hidePopup()
导致组合框关闭其弹出窗口。
|
void |
insertItemAt(E item, int index)
在给定索引的项目列表中插入项目。
|
protected void |
installAncestorListener() |
void |
intervalAdded(ListDataEvent e)
这种方法是公共的,作为实现的副作用。
|
void |
intervalRemoved(ListDataEvent e)
这种方法是公共的,作为实现的副作用。
|
boolean |
isEditable()
如果
JComboBox是可编辑的,则返回true。
|
boolean |
isLightWeightPopupEnabled()
获取
lightWeightPopupEnabled属性的值。
|
boolean |
isPopupVisible()
确定弹出窗口的可见性。
|
protected String |
paramString()
返回此
JComboBox的字符串表示
JComboBox 。
|
void |
processKeyEvent(KeyEvent e)
手柄
KeyEvent s,寻找Tab键。
|
void |
removeActionListener(ActionListener l)
删除
ActionListener 。
|
void |
removeAllItems()
从项目列表中删除所有项目。
|
void |
removeItem(Object anObject)
从项目列表中删除一个项目。
|
void |
removeItemAt(int anIndex)
anIndex删除该项目此方法仅在
JComboBox使用可变数据模型时有效。
|
void |
removeItemListener(ItemListener aListener)
删除
ItemListener 。
|
void |
removePopupMenuListener(PopupMenuListener l)
删除
PopupMenuListener 。
|
protected void |
selectedItemChanged()
这种受保护的方法是具体的实现。
|
boolean |
selectWithKeyChar(char keyChar)
选择与指定键盘字符相对应的列表项,如果存在与该字符相对应的项,则返回true。
|
void |
setAction(Action a)
为
Action设置
ActionEvent源。
|
void |
setActionCommand(String aCommand)
设置应该包含在发送到action监听器的事件中的action命令。
|
void |
setEditable(boolean aFlag)
确定
JComboBox字段是否可编辑。
|
void |
setEditor(ComboBoxEditor anEditor)
设置用于在
JComboBox字段中绘制和编辑所选项目的编辑器。
|
void |
setEnabled(boolean b)
启用组合框,以便可以选择项目。
|
void |
setKeySelectionManager(JComboBox.KeySelectionManager aManager)
设置将键盘字符转换为列表选择的对象。
|
void |
setLightWeightPopupEnabled(boolean aFlag)
设置
lightWeightPopupEnabled属性,它提供了一个提示,一个轻量级的
Component是否应该用于包含
JComboBox ,而重量级
Component ,如
Panel或
Window 。
|
void |
setMaximumRowCount(int count)
设置
JComboBox显示的最大行数。
|
void |
setModel(ComboBoxModel<E> aModel)
设置
JComboBox用于获取项目列表的数据模型。
|
void |
setPopupVisible(boolean v)
设置弹出窗口的可见性。
|
void |
setPrototypeDisplayValue(E prototypeDisplayValue)
设置用于计算UI部分显示大小的原型显示值。
|
void |
setRenderer(ListCellRenderer<? super E> aRenderer)
设置绘制列表项目的渲染器和从JComboBox字段中的列表中选择的项目。
|
void |
setSelectedIndex(int anIndex)
选择索引为
anIndex的项目。
|
void |
setSelectedItem(Object anObject)
将组合框显示区域中的选定项目设置为参数中的对象。
|
void |
setUI(ComboBoxUI ui)
设置渲染此组件的L&F对象。
|
void |
showPopup()
导致组合框显示其弹出窗口。
|
void |
updateUI()
将UI属性重置为当前外观的值。
|
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, 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, updateadd, 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, validateTreeaction, 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, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprotected ComboBoxModel<E> dataModel
protected ListCellRenderer<? super E> renderer
protected ComboBoxEditor editor
protected int maximumRowCount
protected boolean isEditable
isEditable ,
setEditable(boolean)
protected JComboBox.KeySelectionManager keySelectionManager
protected String actionCommand
protected boolean lightWeightPopupEnabled
protected Object selectedItemReminder
public JComboBox(ComboBoxModel<E> aModel)
JComboBox ,从现有的ComboBoxModel获取其项目。
由于提供了ComboBoxModel ,因此使用此构造函数创建的组合框不会创建默认组合框模型,并可能影响插入,删除和添加方法的行为。
aModel -在
ComboBoxModel ,提供显示的项列表
DefaultComboBoxModel
public JComboBox(E[] items)
JComboBox ,其中包含指定数组中的元素。
默认情况下,数组中的第一个项目(因此数据模型)将被选中。
items - 要插入组合框的对象数组
DefaultComboBoxModel
public JComboBox(Vector<E> items)
JComboBox包含指定Vector中的元素。
默认情况下,向量中的第一个项目(因此数据模型)将被选中。
items - 要插入到组合框中的向量数组
DefaultComboBoxModel
public JComboBox()
JComboBox 。
默认数据模型是一个空的对象列表。
使用addItem添加项目。
默认情况下,数据模型中的第一个项目被选中。
DefaultComboBoxModel
protected void installAncestorListener()
public void setUI(ComboBoxUI ui)
ui -
ComboBoxUI L&F对象
UIDefaults.getUI(javax.swing.JComponent)
public void updateUI()
updateUI在
JComponent
JComponent.updateUI()
public String getUIClassID()
getUIClassID在
JComponent
JComponent.getUIClassID() ,
UIDefaults.getUI(javax.swing.JComponent)
public ComboBoxUI getUI()
public void setModel(ComboBoxModel<E> aModel)
JComboBox用于获取项目列表的数据模型。
aModel -在
ComboBoxModel ,提供显示的项列表
public ComboBoxModel<E> getModel()
JComboBox 。
ComboBoxModel ,提供显示的项列表
public void setLightWeightPopupEnabled(boolean aFlag)
lightWeightPopupEnabled属性,其中提供了一个提示是否应该使用轻量级Component来包含JComboBox ,而重量级Component (如Panel或Window 。
轻量级与重量级的决定最终达到JComboBox 。
轻量级的窗口比重型窗口更有效率,但轻量级和重型组件在GUI中不能很好的混合。
如果您的应用程序混合轻量级和重量级组件,则应禁用轻量级弹出窗口。
lightWeightPopupEnabled属性的默认值为true ,除非外观和外观另有规定。
一些看起来和感觉总是使用重量级的弹出窗口,无论这个属性的价值。
请参阅文章Mixing Heavy and Light Components此方法触发属性更改事件。
aFlag - 如果
true ,需要轻量级弹出窗口
public boolean isLightWeightPopupEnabled()
lightWeightPopupEnabled属性的值。
lightWeightPopupEnabled属性
setLightWeightPopupEnabled(boolean)
public void setEditable(boolean aFlag)
JComboBox字段是否可编辑。
可编辑的JComboBox允许用户键入字段或从列表中选择一个项目以初始化该字段,之后可以对其进行编辑。
(编辑仅影响字段,列表项目保持不变。)不可编辑的JComboBox在该字段中显示所选项目,但无法修改选择项。
aFlag - 一个布尔值,其中true表示该字段是可编辑的
public boolean isEditable()
JComboBox是可编辑的,则返回true。
默认情况下,组合框不可编辑。
JComboBox是可编辑的,则为true,否则为false
public void setMaximumRowCount(int count)
JComboBox显示的最大行数。
如果模型中的对象数量大于count,组合框将使用滚动条。
count - 一个整数,指定在使用滚动条之前在列表中显示的最大项目数
public int getMaximumRowCount()
public void setRenderer(ListCellRenderer<? super E> aRenderer)
默认渲染器显示字符串或图标。 其他渲染器可以处理图形图像和复合项目。
要显示所选项目, aRenderer.getListCellRendererComponent ,传递列表对象和索引-1。
aRenderer - 显示所选项目的
ListCellRenderer
setEditor(javax.swing.ComboBoxEditor)
public ListCellRenderer<? super E> getRenderer()
JComboBox字段中用于显示所选项目的渲染器。
ListCellRenderer 。
public void setEditor(ComboBoxEditor anEditor)
JComboBox字段中绘制和编辑所选项目的编辑器。
仅当接收到JComboBox可编辑时才使用编辑器。
如果不可编辑,组合框将使用渲染器来绘制所选项。
anEditor - 显示所选项目的
ComboBoxEditor
setRenderer(javax.swing.ListCellRenderer<? super E>)
public ComboBoxEditor getEditor()
JComboBox字段中用于绘制和编辑所选项目的编辑器。
ComboBoxEditor
public void setSelectedItem(Object anObject)
anObject是在列表中,显示区显示anObject选择。
如果anObject 不在列表中,并且组合框是不可编辑的,则不会更改当前选择。 对于可编辑的组合框,选择将更改为anObject 。
如果这是所选项目的变化,则添加到组合框中的ItemListener将通知一个或两个ItemEvent s。 如果有当前选定的项目, ItemEvent将被触发,状态更改将为ItemEvent.DESELECTED 。 如果anObject在列表中,当前未选择,那么ItemEvent将被触发,状态更改将为ItemEvent.SELECTED 。
ActionListener添加到组合框将被通知一个ActionEvent当这个方法被调用。
anObject - 要选择的列表对象;
使用null清除选择
public Object getSelectedItem()
如果组合框可编辑,则该值可能没有被添加到组合框addItem , insertItemAt或数据构造。
setSelectedItem(java.lang.Object)
public void setSelectedIndex(int anIndex)
anIndex的项目。
anIndex - 指定要选择的列表项的整数,其中0指定列表中的第一个项,-1表示不选择
IllegalArgumentException - 如果
anIndex <-1或
anIndex大于或等于大小
public int getSelectedIndex()
JComboBox允许不在列表中的所选项目,则结果并不总是被定义。
如果没有选定项目,或者用户指定了不在列表中的项目,则返回-1。
public E getPrototypeDisplayValue()
prototypeDisplayValue属性
setPrototypeDisplayValue(E)
public void setPrototypeDisplayValue(E prototypeDisplayValue)
如果指定了原型显示值,则通过使用原型显示值配置渲染器并获得其首选大小来计算组合框的首选大小。 当组合框显示大量数据时,指定首选显示值通常很有用。 如果没有指定原型显示值,则必须为模型中的每个值配置渲染器和获取的首选尺寸,这可能相对昂贵。
prototypeDisplayValue -
getPrototypeDisplayValue()
public void addItem(E item)
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 - 要添加到列表中的项目
MutableComboBoxModel
public void insertItemAt(E item, int index)
JComboBox使用可变数据模型时有效。
item - 要添加到列表的项目
index - 指定要添加项目的位置的整数
MutableComboBoxModel
public void removeItem(Object anObject)
JComboBox使用可变数据模型时有效。
anObject - 要从项目列表中删除的对象
MutableComboBoxModel
public void removeItemAt(int anIndex)
anIndex删除该项目此方法仅在
JComboBox使用可变数据模型时有效。
anIndex - 一个int指定要删除的项目的索引,其中0表示列表中的第一个项目
MutableComboBoxModel
public void removeAllItems()
public void showPopup()
setPopupVisible(boolean)
public void hidePopup()
setPopupVisible(boolean)
public void setPopupVisible(boolean v)
public boolean isPopupVisible()
public void addItemListener(ItemListener aListener)
ItemListener 。
aListener将在所选项目更改时收到一个或两个ItemEvent 。
addItemListener在接口
ItemSelectable
aListener - 要通知的
ItemListener
setSelectedItem(java.lang.Object)
public void removeItemListener(ItemListener aListener)
ItemListener 。
removeItemListener在接口
ItemSelectable
aListener - 要删除的
ItemListener
ItemEvent
public ItemListener[] getItemListeners()
ItemListener的数组。
ItemListener s或一个空数组
public void addActionListener(ActionListener l)
ActionListener 。
ActionListener将在ActionEvent时收到ActionEvent 。 如果组合框是可编辑的,则编辑停止时将会触发ActionEvent 。
l - 要通知的
ActionListener
setSelectedItem(java.lang.Object)
public void removeActionListener(ActionListener l)
ActionListener 。
l - 要删除的
ActionListener
public ActionListener[] getActionListeners()
ActionListener的数组。
ActionListener加入一个空数组,如果没有添加侦听器,
public void addPopupMenuListener(PopupMenuListener l)
PopupMenu监听器,它将从组合框的弹出窗口中收听通知消息。
对于Java附带的所有标准外观和感觉,组合框的弹出列表部分实现为JPopupMenu 。 自定义外观可能无法实现,因此不会收到通知。
l - 要添加的
PopupMenuListener
public void removePopupMenuListener(PopupMenuListener l)
PopupMenuListener 。
l - 要删除的
PopupMenuListener
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public PopupMenuListener[] getPopupMenuListeners()
PopupMenuListener的数组。
PopupMenuListener或者如果没有添加任何监听器,则为空数组
public void firePopupMenuWillBecomeVisible()
PopupMenuListener s组合框的弹出部分将变得可见。
这个方法是公开的,但不应该被UI委托以外的任何东西调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void firePopupMenuWillBecomeInvisible()
PopupMenuListener s组合框的弹出部分变得不可见。
这个方法是公开的,但不应该被UI委托以外的任何东西调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void firePopupMenuCanceled()
PopupMenuListener s组合框的弹出部分已被取消。
这个方法是公开的,但不应该被UI委托以外的任何东西调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void setActionCommand(String aCommand)
aCommand - 一个包含发送到动作侦听器的“命令”的字符串;
同样的听众可以根据接收到的命令来做不同的事情
public String getActionCommand()
public void setAction(Action a)
Action设置ActionEvent来源。
新Action替换任何以前设置Action但不影响ActionListeners与单独添加addActionListener 。
如果Action已经是ActionEvent的注册ActionListener为ActionEvent ,则不会重新注册。
设置Action会导致立即更改Swing Components Supporting Action中描述的所有属性 。 随后,组合框的属性将自动更新为Action的属性更改。
此方法使用其他三种方法来设置和帮助跟踪Action的属性值。 它使用configurePropertiesFromAction方法立即更改组合框的属性。 要跟踪Action的属性值的更改,此方法注册PropertyChangeListener返回的createActionPropertyChangeListener 。 默认PropertyChangeListener调用actionPropertyChanged方法时的属性Action变化。
a -
Action为
JComboBox ,或
null 。
Action , getAction() , configurePropertiesFromAction(javax.swing.Action) , createActionPropertyChangeListener(javax.swing.Action) , actionPropertyChanged(javax.swing.Action, java.lang.String)
public Action getAction()
Action为
ActionEvent源,或
null如果没有设置
Action 。
Action为这ActionEvent源码;
或null
Action , setAction(javax.swing.Action)
protected void configurePropertiesFromAction(Action a)
Action 。
有关此设置的属性的更多详细信息,请参阅Swing Components Supporting Action 。
a -
Action从哪个获取属性,或
null
Action , setAction(javax.swing.Action)
protected PropertyChangeListener createActionPropertyChangeListener(Action a)
PropertyChangeListener ,负责监听来自指定的变化Action和更新相应的属性。
警告:如果你这个子类不创建一个匿名的内部类。 如果你一生的组合框将被绑定到Action 。
a - 组合框的动作
Action , setAction(javax.swing.Action)
protected void actionPropertyChanged(Action action, String propertyName)
PropertyChangeListener从返回createActionPropertyChangeListener 。
子类通常不需要调用它。
支持额外Action Action子类应该覆盖此和configurePropertiesFromAction 。
有关此方法设置的属性的列表,请参阅Swing Components Supporting Action的表。
action - 与此组合框相关
Action Action
propertyName - 更改的属性的名称
Action , configurePropertiesFromAction(javax.swing.Action)
protected void fireItemStateChanged(ItemEvent e)
e - 感兴趣的事件
EventListenerList
protected void fireActionEvent()
EventListenerList
protected void selectedItemChanged()
public Object[] getSelectedObjects()
ItemSelectable兼容而ItemSelectable 。
getSelectedObjects在接口
ItemSelectable
Objects数组 - 所选项
public void actionPerformed(ActionEvent e)
actionPerformed在接口
ActionListener
public void contentsChanged(ListDataEvent e)
contentsChanged在界面
ListDataListener
e -
ListDataEvent ListDataEvent封装事件信息
public void intervalAdded(ListDataEvent e)
intervalAdded在接口
ListDataListener
e -
ListDataEvent ListDataEvent封装事件信息
public void intervalRemoved(ListDataEvent e)
intervalRemoved在界面
ListDataListener
e -一个
ListDataEvent封装事件信息
public boolean selectWithKeyChar(char keyChar)
keyChar - 一个char,通常这是用户键入的键盘键
public void setEnabled(boolean b)
setEnabled在
JComponent
b - 一个布尔值,其中true使组件和false禁用它
Component.isEnabled() ,
Component.isLightweight()
public void configureEditor(ComboBoxEditor anEditor, Object anItem)
anEditor - 在组合框字段中显示列表项的
ComboBoxEditor ,允许编辑
anItem - 要在字段中显示和编辑的对象
public void processKeyEvent(KeyEvent e)
KeyEvent s,寻找Tab键。
如果找到Tab键,弹出窗口关闭。
processKeyEvent在
JComponent
e -
KeyEvent按下的键盘键的
KeyEvent
KeyEvent , KeyListener , KeyboardFocusManager , DefaultKeyboardFocusManager , Component.processEvent(java.awt.AWTEvent) , Component.dispatchEvent(java.awt.AWTEvent) , Component.addKeyListener(java.awt.event.KeyListener) , Component.enableEvents(long) , Component.isShowing()
public void setKeySelectionManager(JComboBox.KeySelectionManager aManager)
public JComboBox.KeySelectionManager getKeySelectionManager()
KeySelectionManager使用的
KeySelectionManager
public int getItemCount()
public E getItemAt(int index)
index超出范围(小于零或大于或等于大小),它将返回null 。
index - 表示列表位置的整数,第一个项目从零开始
null
protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
KeySelectionManager目前使用的
KeySelectionManager
setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager)
protected String paramString()
JComboBox的字符串表示JComboBox 。
该方法仅用于调试目的,并且返回的字符串的内容和格式可能因实现而异。
返回的字符串可能为空,但可能不是null 。
paramString在
JComponent
JComboBox的字符串表示
JComboBox
public AccessibleContext getAccessibleContext()
getAccessibleContext在界面
Accessible
getAccessibleContext在
Component
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.