2016-05-30 21 views
0

我有一個組合框,我填寫並選擇所需的項目與selectedItem但不selectedIndex。SetSelectedItem不會跳到選定的項目後點擊框

在selectedIndex的情況下,它在組合框中設置所需的值,並突出顯示選擇。但在selectedItem的情況下,它會選擇我需要的東西,但是當我按下框時,它會顯示從最初開始的列表。

如何在不使用setSelectedIndex的情況下設置選定的項目?

回答

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. 
相關問題