I know this isn't the only question about filling JLists, but I didn't find the answer in another SO thread.
I've used the Netbeans GUI builder to create my GUI. The JList is added to a scrollpane, if I hardcode the content of the JList everything is showed fine.
jList1.setModel(new javax.swing.AbstractListModel() {
public String[] strings = {"1", "2", "etc..."};
@Override
public int getSize() {
return strings.length;
}
@Override
public Object getElementAt(int i) {
return strings[i];
}
});
But if I try to add items dynamically via SwingWorker
, nothing appears.
JList jList1 = new javax.swing.JList();
DefaultListModel info = new DefaultListModel();
....
jList1.setModel(info);
....
public void FillList(final String subject) {
worker = new SwingWorker() {
@Override
protected Object doInBackground() {
info.addElement(subject);
return 0;
}
@Override
protected void done() {
}
};
worker.execute();
}
I just want to show the subjects in the JList for visual purposes, the rest is done in the background.
Any help is appreciated,
Thanks!