E
-这个组合框的元素类型
public class JComboBox<E> extends JComponent implements ItemSelectable, ListDataListener, ActionListener, Accessible
警告: Swing是线程不安全的。更多信息见Swing's Threading Policy。
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为1.4,为所有JavaBeans™长期存储的支持已被添加到java.beans
包。请看XMLEncoder
。
Modifier and Type | Class and Description |
---|---|
protected class |
JComboBox.AccessibleJComboBox
这个类实现了对
JComboBox 类可访问性支持。
|
static interface |
JComboBox.KeySelectionManager
定义一个
KeySelectionManager 接口。
|
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.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_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, 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 包含在指定的向量元素。
|
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 。
|
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()
获取与此相关的accessiblecontext JComboBox。
|
Action |
getAction()
返回当前设置为这个
ActionEvent 源
Action ,或
null 如果没有
Action 设置。
|
String |
getActionCommand()
返回包含在发送给行动侦听器的事件中的动作命令。
|
ActionListener[] |
getActionListeners()
返回所有的
ActionListener s数组添加到这个JComboBox和addactionlistener()。
|
ComboBoxEditor |
getEditor()
用于油漆和在
JComboBox 场编辑选定的项目编辑器返回。
|
E |
getItemAt(int index)
返回指定索引中的列表项。
|
int |
getItemCount()
返回列表中的项目数。
|
ItemListener[] |
getItemListeners()
返回所有的
ItemListener s数组添加到这个JComboBox和additemlistener()。
|
JComboBox.KeySelectionManager |
getKeySelectionManager()
返回列表的密钥选择管理器。
|
int |
getMaximumRowCount()
返回组合框可以显示没有滚动条的最大项数
|
ComboBoxModel<E> |
getModel()
返回的数据模型目前使用的
JComboBox 。
|
PopupMenuListener[] |
getPopupMenuListeners()
返回所有的
PopupMenuListener s数组添加到这个JComboBox和addpopupmenulistener()。
|
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 字符串表示形式。
|
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)
选择对应于指定的键盘字符的列表项,并返回真的,如果有一个对应于该字符的项目。
|
void |
setAction(Action a)
设置为
ActionEvent 源
Action 。
|
void |
setActionCommand(String aCommand)
设置应包含在发送给操作侦听器的事件中的操作命令。
|
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)
设置用于计算用户界面部分显示的大小的原型显示值。
|
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, update
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
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, 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, transferFocusUpCycle
protected 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
包含在指定的向量元素。默认情况下,向量中的第一个项目(因此数据模型)被选中。
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
。轻量级的窗口比重量级的窗口更有效,但轻量级和重量级的组件在一个图形用户界面中并不混合。如果你的应用程序和轻量级和重量级组件,你应该禁用轻量级的弹出窗口。为
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
-一个布尔值,真正表明场编辑
public boolean isEditable()
JComboBox
编辑返回true。默认情况下,组合框不可编辑。
JComboBox
编辑真的,其他的错误
public void setMaximumRowCount(int count)
JComboBox
最大数显示。如果模型中的对象的数目大于计数,组合框使用滚动条。
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
s添加到组合框将有一个或两个ItemEvent
s通知。如果有当前选定的项目,一个ItemEvent
将解雇和状态的变化,将ItemEvent.DESELECTED
。如果anObject
列表中不选中然后ItemEvent
将解雇和状态的变化,将ItemEvent.SELECTED
。
ActionListener
s添加到组合框将一个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
使用可变数据模型的方法。
警告:焦点和键盘如果你添加重复的字符串对象可能出现导航问题。一个解决方法是添加新的对象而不是字符串对象,确保tostring()方法定义。例如:
组合框。addItem(makeobj(“项目1”));组合框。addItem(makeobj(“项目1”));…私有对象makeobj(最终串项){返回新的object() { public String tostring() {返回项目;} };}
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
s当选定项的变化。
addItemListener
接口
ItemSelectable
aListener
-
ItemListener
是通知
setSelectedItem(java.lang.Object)
public void removeItemListener(ItemListener aListener)
ItemListener
。
removeItemListener
接口
ItemSelectable
aListener
-
ItemListener
删除
ItemEvent
public ItemListener[] getItemListeners()
ItemListener
s数组添加到这个JComboBox和additemlistener()。
ItemListener
s说如果没有听众已添加一个空数组
public void addActionListener(ActionListener l)
ActionListener
。
的ActionListener
将收到一ActionEvent
当选择了。如果组合框是可编辑的,然后ActionEvent
将解雇当编辑已经停止。
l
-
ActionListener
是通知
setSelectedItem(java.lang.Object)
public void removeActionListener(ActionListener l)
ActionListener
。
l
-
ActionListener
删除
public ActionListener[] getActionListeners()
ActionListener
s数组添加到这个JComboBox和addactionlistener()。
ActionListener
s说如果没有听众已添加一个空数组
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
s数组添加到这个JComboBox和addpopupmenulistener()。
PopupMenuListener
s说如果没有听众已添加一个空数组
public void firePopupMenuWillBecomeVisible()
PopupMenuListener
s,组合框弹出的部分会变得可见。
此方法是公共的,但不应该被任何其他比用户界面委托的任何调用调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void firePopupMenuWillBecomeInvisible()
PopupMenuListener
s,组合框弹出部分已看不见。
此方法是公共的,但不应该被任何其他比用户界面委托的任何调用调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void firePopupMenuCanceled()
PopupMenuListener
s,组合框弹出的部分已被取消。
此方法是公共的,但不应该被任何其他比用户界面委托的任何调用调用。
addPopupMenuListener(javax.swing.event.PopupMenuListener)
public void setActionCommand(String aCommand)
aCommand
-一个包含“命令”发送到监听行动;相同的听众可以做不同的事情取决于它接收到的命令
public String getActionCommand()
public void setAction(Action a)
ActionEvent
源
Action
。新
Action
取代任何先前设定的
Action
但不影响
ActionListeners
独立加
addActionListener
。如果
Action
已经注册
ActionListener
为
ActionEvent
源,不重新登记。
立即改变所有的属性描述 Swing Components Supporting Action
设置Action
结果。随后,ComboBox的属性为Action
特性改变的自动更新。
该方法采用其他三种方法来设置和帮助跟踪Action
的属性值。它使用configurePropertiesFromAction
法立即改变组合框的属性。跟踪在Action
的属性值的变化,该方法返回的PropertyChangeListener
createActionPropertyChangeListener
寄存器。默认PropertyChangeListener
调用actionPropertyChanged
方法在Action
变化特性。
a
为
JComboBox
的
Action
,或
null
。
Action
,
getAction()
,
configurePropertiesFromAction(javax.swing.Action)
,
createActionPropertyChangeListener(javax.swing.Action)
,
actionPropertyChanged(javax.swing.Action, java.lang.String)
public Action getAction()
ActionEvent
源
Action
,或
null
如果没有
Action
设置。
ActionEvent
源
Action
;或
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
变化和更新相应的属性。
警告:如果子类不创建一个匿名内部类。如果你的一生将ComboBox绑定到的Action
。
a
- ComboBox的行动
Action
,
setAction(javax.swing.Action)
protected void actionPropertyChanged(Action action, String propertyName)
PropertyChangeListener
调用返回
createActionPropertyChangeListener
。子类通常不需要调用这个。子类,支持额外的
Action
性能应重写此和
configurePropertiesFromAction
。
引用该表在属性的列表方法 Swing Components Supporting 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
。
getSelectedObjects
接口
ItemSelectable
Objects
选定项目
public void actionPerformed(ActionEvent e)
actionPerformed
接口
ActionListener
public void contentsChanged(ListDataEvent e)
contentsChanged
接口
ListDataListener
e
-
ListDataEvent
封装事件信息
public void intervalAdded(ListDataEvent e)
intervalAdded
接口
ListDataListener
e
-
ListDataEvent
封装事件信息
public void intervalRemoved(ListDataEvent e)
intervalRemoved
接口
ListDataListener
e
-
ListDataEvent
封装事件信息
public boolean selectWithKeyChar(char keyChar)
keyChar
-一个字符,通常这是一个键盘按键的用户输入
public void setEnabled(boolean b)
setEnabled
方法重写,继承类
JComponent
b
-一个布尔值,真正使组件和假禁用它
Component.isEnabled()
,
Component.isLightweight()
public void configureEditor(ComboBoxEditor anEditor, Object anItem)
anEditor
-显示列表项的组合框中的字段,可以编辑
ComboBoxEditor
anItem
——展示和现场编辑对象
public void processKeyEvent(KeyEvent e)
KeyEvent
s,寻找Tab键。如果标签的关键是发现,弹出的窗口关闭。
processKeyEvent
方法重写,继承类
JComponent
e
含键盘被按下键
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
public int getItemCount()
public E getItemAt(int index)
index
超出范围(小于零或大于或等于大小)将返回
null
。
index
-一个整数列表中的位置,其中第一项的从零开始
null
如果超出范围
protected JComboBox.KeySelectionManager createDefaultKeySelectionManager()
KeySelectionManager
setKeySelectionManager(javax.swing.JComboBox.KeySelectionManager)
protected String paramString()
JComboBox
字符串表示形式。此方法仅用于调试目的,返回的字符串的内容和格式可能会在实现过程中有所不同。返回的字符串是空的但可能不
null
。
paramString
方法重写,继承类
JComponent
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.