JList和ComboBox很相似,因为这两个组件都显示一个项列表。因此,它们都有扩展ListModel接口的模型。而且,这两个组件都有绘制器,这些绘制器通过实现ListCellBenderer接口来绘制列表单元。
列表支持三个选取模式,并把选取工作实现ListSelectionModel接口的一个对象来处理。组合框在一个时刻只有一个可选取的项,而且选取工作由组合框模型来处理。另一方面,组合框支持键选取,即在某项上按下一下键就可以选取这个项,但列表不能这样做。
构造函数
JComboBox()
JComboBox(ComboBoxModel aModel)
JComboBox(Object[] items)
JComboBox(Vector<?> items)
常用方法
addActionListener(ActionListener l)
addItem(Object anObject)
addItemListener(ItemListener aListener)
configureEditor(ComboBoxEditor anEditor, Object anItem)
getEditor()
getItemAt(int index)
getItemCount()
getModel()
getRenderer()
getSelectedIndex()
getSelectedItem()
insertItemAt(Object anObject, int index)
isEditable()
removeAllItems()
removeItem(Object anObject)
removeItemAt(int anIndex)
setModel(ComboBoxModel aModel)
setRenderer(ListCellRenderer aRenderer)
setSelectedIndex(int anIndex)
setSelectedItem(Object anObject)
Swing__JComboBox 用法
最新推荐文章于 2022-11-02 09:45:48 发布