I am trying to add and remove elements from jList (jList1), but this will not work. I searched stackoverflow for other people with the same problem, but when their problem is resolved, I keep getting errors. So this is how I declared jList:
jList1.setModel(new javax.swing.AbstractListModel() {
String [] strings = lijstItems;
public int getSize() {
return strings.length;
}
public Object getElementAt (int i) {
return strings[i];
}
});
So, now I made these buttons to add and remove items from the list:
private void addHostActionPerformed(java.awt.event.ActionEvent evt) {
DefaultListModel model = (DefaultListModel) jList1.getModel();
model.add(2, "item");
}
and
private void deleteHostActionPerformed(java.awt.event.ActionEvent evt) {
}
I tried so many things, but they do not work! Can anybody help me?
Thank!
source
share