I have 12 labels and 12 car objects in an ArrayList. The for loop sets the for each label and its corresponding car object. However the text in the labels does not wrap and just carries on.
What do I have to put in the loop to make the text wrap?
In theory the text is supposed to look like this:
2012 Toyota Corolla
70000 Miles
$12,000.00
But instead in the labels all I get in a single line is:
2012 Toyota Corolla 700...
Code
InventoryFileReader reader = new InventoryFileReader();
ArrayList<Car> cars = reader.getAllCars();
//will format getPrice to currency.
Locale locale = new Locale("en", "US");
NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
JLabel[] labels = new JLabel[]{jLabel1, jLabel2, jLabel3, jLabel4,
jLabel5, jLabel6, jLabel7, jLabel8,
jLabel9, jLabel10, jLabel11, jLabel12};
for(int i = 0; labels.length > i; i ++){
labels[i].setText(cars.get(i).getYear() + " " + cars.get(i).getMake() +
" " + cars.get(i).getModel() + " " + "\n" + cars.get(i).getMiles()
+ " miles" + '\n' + " " + formatter.format(cars.get(i).getPrice()));
}
The getYear(), getMiles(), and getPrice(), actually return integer values.