【问题标题】:SetSelectedItem doesnt jump to selected item after clicking the boxSetSelectedItem 在单击框后不会跳转到选定的项目
【发布时间】:2016-05-30 10:27:01
【问题描述】:
我有一个组合框,我用 selectedItem 但不使用 selectedIndex 填充并选择所需的项目。
在 selectedIndex 的情况下,它在组合框中设置所需的值,并突出显示选择。但是在 selectedItem 的情况下,它会选择我需要的内容,但是当我按下该框时,它会从一开始就显示列表。
如何在不使用 setSelectedIndex 的情况下设置选中项?
【问题讨论】:
标签:
java
combobox
selecteditem
【解决方案1】:
如果你在这里发布代码会更好。但是.. 请阅读下面关于 setSelectedItem 的 javaDocs 文本:
Sets the selected item in the combo box display area to the object in the argument. If anObject is in the list, the display area shows anObject selected.
If anObject is not in the list and the combo box is uneditable, it will not change the current selection. For editable combo boxes, the selection will change to anObject.
If this constitutes a change in the selected item, ItemListeners added to the combo box will be notified with one or two ItemEvents. If there is a current selected item, an ItemEvent will be fired and the state change will be ItemEvent.DESELECTED.If anObject is in the list and is not currently selected then an ItemEvent will be fired and the state change will be ItemEvent.SELECTED.