Using
list0.setModel(new DefaultComboBoxModel(toTable.data));
I can update the whole JComboBox (list0)... but I want to add a few lines to it (need to have few different positions to choose from on my list). When I'm using this command, it makes an update but everytime in first line of JComboBox. That means I will have only one position in my JComboBox in the end.
I tried
list0.setModel(new DefaultComboBoxModel(toTable.data[x]));
but it's not working. Any ideas?
(x-number of line)
I'm, not exactly sure what you're asking, but it seems like you just want to add elements dynamically to a
JComboBox
. You seem to have the right idea, using theDefaultComboBoxModel
. To add a new element the list, useSee DefaulComboBoxModel for more methods.
Here's a simple example. Just type something in the text field, and hit enter. Here's the important code I used
Here the complete program