Issue
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?
Solution
addElement
is provided by the DefaultListModel
not the JList
itself
DefaultListModel<String> model = new DefaultListModel<>();
JList jListResult = new JList(model);
model.addElement(...);
Answered By - Reimeus
Answer Checked By - Pedro (JavaFixing Volunteer)