Hi, I've been searching all the internet for an answer for my problem, but none of the sites I've stumbled upon haven't given any results.
So, I have a JList, held inside JSCrollPane, held inside JPanel inside JFrame. I have a MySQL database, and another block of code retrieves stuff from there and puts it in a vector<String>. When I update the JLists ListModel to hold the exact same information as the vector, the JList doesn't update the results. I have only a blank JList as a result. :/
Here's some code of the problem.
// Cleaned version of the MainUI file, which creates the elements
public class MainUI {
private JScrollPane seriesPane;
private DefaultListModel lmSeries;
private JList seriesList;
private
MainUI(Main main_par) {
mControl = main_par;
createUI();
}
private void createUI() {
....
lmSeries = new DefaultListModel();
seriesPane = new JScrollPane();
seriesList = new JList();
seriesPane.add(seriesList);
seriesPanel = new JPanel();
seriesPanel.add(seriesPane);
....
}
void listSeries(Vector v) {
DefaultListModel lm = (DefaultListModel) seriesList.getModel();
lm.removeAllElements();
for(int i = 0; i < v.size(); i++) {
lm.add(i, v.elementAt(i));
System.err.println("added: " + lm.lastElement());
}
}
}
The println in listSeries() method prints out all the lines correctly, so the ListModel does get updated. I'm running the main program in InvokeLater(), so I guess it should invoke the event dispatch thread..?