JTable's JComboBox cell editor sets the value already when opening the list, even if clicked outside the combo-box

前端 未结 1 1102
北海茫月
北海茫月 2021-01-21 09:40

JTable\'s JComboBox cell editor sets the value already when opening the list, even if clicked outside the combo-box. Moreover, once certain value selec

相关标签:
1条回答
  • 2021-01-21 10:29

    Your problem is because the current cell value is not one of the possible selections of the combobox editor, and so the combo defaults to the first selection. If you change your editor to include the current values, e.g.,

    DefaultCellEditor cellEditor = new DefaultCellEditor(
            new JComboBox<>(new Integer[] { 1, 2,3, 4, 5, 6, 7, 8, 9 }));
    

    Then it works just fine and as expected.

    If you want a more fine-grained control over the editor, then you'll want to roll your own and not use the default one.

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