The bottom line:
I can’t assign a list of my items to a button-list
there is
ArrayList<String> users = new ArrayList(); there is also a line in the class with a GUI
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); I work in NetBeans, I can’t assign my list to the list button. On foreign internet I found this:
jComboBox1.removeAllItems(); for (int i = 0; i < users.size(); i++) { jComboBox1.addItem(users.get(i)); } PROBLEMS OF ATTACHED BELOW ANSWERS:
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"})); jComboBox1.removeAllItems(); String [] items = new String [10]; for (int i = 0; i < new ListFriend().nameSurname.size(); i++) { items[i] = new ListFriend().nameSurname.get(i); } jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(items)); As a result, I received the elements, but they are not displayed. What is the reason?
jComboBox1.setModel(myModel); myModel.add("Hello"); myModel.add("Hel23lo"); myModel.add("Hell3wso"); for (int i = 0; i < new ListFriend().nameSurname.size(); i++) { String r = new ListFriend().nameSurname.get(i); myModel.add(r); } If you try this, it also does not work, it does not throw the elements of the array into the list, except for those that were added through just myModel.add, it does not allow you to add through a cycle.
If you even write this:
for (int i = 0; i < 5; i++) { String r = "hello world"; new MyModel().add(r); } he will not add them anyway.
