I have a JList which is set to an ArrayList of days.
public void setCalender(ArrayList<Day> calender) {
this.calender = calender;
listDays.setListData(this.calender.toArray());
}
Each day contains a date/id and 3 periods:
public class Day {
private int date;
private Period p1;
private Period p2;
private Period p3;
public Day(int date) {
this.date = date;
p1 = new Period(1);
p2 = new Period(2);
p3 = new Period(3);
}
}
When the list renders, it shows each list item as “kkbs.Day@4d182e1e” for instance.
Is there any way to make a fixed string to show the user (i.e Day1), while still keeping the whole object in the list to retrieve?
Use a custom cell renderer for the list to format the view as required. Alternately you might define a
toString()for the object, but the renderer is more versatile.