Reputation: 202
This is the automatically created code when adding the Jlist in Netbeans design mode:
jListResult = new javax.swing.JList();
jListResult.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(jListResult);
I don't understand why an object of type Jlist would not be able to use the method .addElement How can I fix this?
Upvotes: 0
Views: 539
Reputation: 159754
addElement
is provided by the DefaultListModel
not the JList
itself
DefaultListModel<String> model = new DefaultListModel<>();
JList jListResult = new JList(model);
model.addElement(...);
Upvotes: 4