- AddCarScreen - где сотрудники могут добавить новый автомобиль
- StaffCarListingScreen - где jlist отображает все добавленные Cars
после добавления автомобиля и щелчка "Просмотреть списки автомобилей" , Jlist появляется пустым или не показывает обновленный автомобиль. это: < /p>
btnAddCarScreen.addActionListener(e -> {
main.createStaffCarListingScreen(); // switches to car listing screen
carListing.populateList(); // this tries to refresh the JList
});
Inside the "populateList()" method, I do this:
public void populateList() {
car = this.main.getCarManager().getAllCar();
DefaultListModel model = new DefaultListModel();
for (int i = 0; i < car.size(); i++) {
Car temp = car.get(i);
String display = "Brand: " + temp.getBrand() + " ModelName: " + temp.getModelName() + " VehicleType: " + temp.getVehicleType() + " FuelType: " + temp.getFuelType()
+ " Registration Year: " + temp.getRegistrationYear() + " Transmission: " + temp.getTransmission() + " License Plate: " + temp.getLicensePlate() + " Price/Day: " + temp.getCostPerDay();
model.addElement(display);
System.out.print("Updated JList");
}
this.list.setModel(model);
}
I get back "Updated JList" on the console, however list is still empty not updated.
Подробнее здесь: https://stackoverflow.com/questions/796 ... cardlayout