这是我的代码:
private static final long serialVersionUID = 1L;
/* The data as a list of Persons.
*/
private static List<PersonModel> personData = new ArrayList<PersonModel>();
public static JList<PersonModel> jlist;
public void init() {
// Add some sample data
personData.add(new PersonModel("Hans", "Muster"));
personData.add(new PersonModel("Ruth", "Mueller"));
personData.add(new PersonModel("Heinz", "Kurz"));
personData.add(new PersonModel("Cornelia", "Meier"));
personData.add(new PersonModel("Werner", "Meyer"));
personData.add(new PersonModel("Lydia", "Kunz"));
personData.add(new PersonModel("Anna", "Best"));
personData.add(new PersonModel("Stefan", "Meier"));
personData.add(new PersonModel("Martin", "Mueller"));
String dataQ = " ";
for(int i = 0; i < personData.size(); i++){
dataQ = personData.get(i).getLastName() + " " + personData.get(i).getFirstName();
}
String[] arr = new String[] { dataQ };
jlist = new JList(arr);
但它只显示最后一条记录。如何显示所有记录/值?有任何想法吗?谢谢。