0
我有一些物體orderProperty釉面列表排序列表更新時,源對象爲了改變性質
class Car
{
private int order;
// getter and setter implementation
}
然後,我創建EVENTLIST:
EventList<Car> cars=new BasicEventList<Car>()
for (i=0;i<10;i++) {Car car=new Car(i); cars.add(car);}
然後,我創建排序列表基於汽車使用它的TableModel
SortedList<Car> sortedCars=new SortedList<Car>(cars,carsComparator);
這裏是比較器:
Comparator<Car> carsComparator implements Comparator<Car>
{
@Override
public int compare(Car o1, Car o2) {
return o1.getOrder() - o2.getOrder();
}
}
在程序中有一些事件會改變car.order屬性。如何通知有關此更改的列表?
我發現了一個醜陋但簡單的解決方案:在任何訂單屬性更改後調用Collections.sort(sortedCars,carsComparator) –