sortedControls.add(controls[i]);
}
Collections.sort(sortedControls,new Comparator() {
public int compare(Object o1, Object o2) {
Control c1 = (Control) o1;
Control c2 = (Control) o2;
Object layoutData1 = c1.getLayoutData();
Object layoutData2 = c2.getLayoutData();
if(layoutData1 == null || ! (layoutData1 instanceof SimpleReorderableListLayoutData) ) return 0;
if(layoutData2 == null || ! (layoutData2 instanceof SimpleReorderableListLayoutData) ) return 0;
SimpleReorderableListLayoutData data1 = (SimpleReorderableListLayoutData) layoutData1;
SimpleReorderableListLayoutData data2 = (SimpleReorderableListLayoutData) layoutData2;
return data1.position - data2.position;
}
});
for(int i = 0 ; i < sortedControls.size() ; i++) {
int xn = i % itemsPerRow;
int yn = i / itemsPerRow;
Control control = (Control) sortedControls.get(i);
//int x = borderW + (margin + maxWidth + extraSpacing) * xn + extraSpacing;
int x = borderW + (margin + maxWidth + extraSpacing) * xn;
int y = borderH + (margin + maxHeight) * yn;
control.setLocation(x,y);
//control.setBounds(x,y,maxWidth,maxHeight);
control.setBounds(x,y,maxWidth + extraSpacing,maxHeight);
}
}