Bagelstein
Bagelstein

Reputation: 202

JList created in Netbeans won't allow me to addElement

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

Answers (1)

Reimeus
Reimeus

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

Related Questions