Java swing: implementing my Comboboxmodel for JComboBox

后端 未结 1 1248
闹比i
闹比i 2021-01-17 04:55

I need my combo box to have short names of organizations. The problem is i can see organizations names in dropdown list, but cant actually

相关标签:
1条回答
  • 2021-01-17 05:32

    I suspect it's that your setSelectedItem() method compares objects using == rather than .equals()

    Consider using a DefaultComboBoxModel which already implements useful methods.

    Edit: Also according to the Docs you should be calling all registered ListDataListener objects when setSelected is called.

    Using a DefaultComboBoxModel is fairly straightforward. You create a new DefaultComboBoxModel add the elements you want it to contain then call getSelectedItem() to retrieve the element that is currently selected.

    0 讨论(0)
提交回复
热议问题