Search code examples
javaswingjlistdatamodel

JList not showing items or showing selectively


I have a Java Swing application using a JList to show some data from a DB.

I am using DefaulListModel as the data model for the list in this way:

void PopulateSoldiersList() 
{
      try
      {
           soldiersListModel = new DefaultListModel();
           for (Soldier i : myBackEnd.GetAllSoldiers())
           {
                 soldiersListModel.addElement(i);
           }
           this.listSoldiers.setModel(soldiersListModel);
      }
      catch (Exception ex) {// Error Message}
}

And for some reason, the list just stays empty...

I even did make sure at runtime that all the data is set up properly in the data model and even in the "dataModel" property of the JList!

In other place at the app i have a similar problem, but there, sometimes the list show few items from the model (but not all of them)

I have no idea where to go from here...

please help. Thanks!


Solution

  • False alarm.

    I really need to kill myself.

    I have another list, and i used similar methods to populate both lists.

    Actually they so similar that i just copy-pasted the method i posted above - to populate the other list.

    In my infinite wisdom i forgot to change only one thing: the name of the list which i'm setting the data model for...

    So i ended up with two methods that populate the same list: the firs one with valid data, and the second just override it with empty data.

    and guess in what order i called the methods...

    myBackEnd = new DBBackEnd();
    initComponents();
    PopulateSoldiersList();
    PopulateMissionsList();
    

    No more copy-paste for me!