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) –