单击该框后,SetSelectedItem不会跳转到所选项目

时间:2016-05-30 10:27:01

标签: java combobox selecteditem

我有一个组合框,我填充并使用selectedItem选择所需的项目但不选择selectedIndex。

如果是selectedIndex,它会在组合框中设置所需的值,并突出显示所选内容。但是如果是selectedItem,它会选择我需要的东西,但是当我按下它时,它会显示从最开始的列表。

如何在不使用setSelectedIndex?

的情况下设置所选项目

1 个答案:

答案 0 :(得分:0)

如果您在此处发布代码会更好。但是..请从javaDocs中读取以下关于setSelectedItem的文本:

 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.