}
if (paintables != null) {
- // Sorts the Paintable list so that parents
- // are always painted before children
+ // We need to avoid painting children before parent.
+ // This is ensured by ordering list by depth in component
+ // tree
Collections.sort(paintables, new Comparator() {
public int compare(Object o1, Object o2) {
- final Component c1 = (Component) o1;
- final Component c2 = (Component) o2;
- if (isChildOf(c1, c2)) {
+ Component c1 = (Component) o1;
+ Component c2 = (Component) o2;
+ int d1 = 0;
+ while (c1.getParent() != null) {
+ d1++;
+ c1 = c1.getParent();
+ }
+ int d2 = 0;
+ while (c2.getParent() != null) {
+ d2++;
+ c2 = c2.getParent();
+ }
+ if (d1 < d2) {
return -1;
}
- if (isChildOf(c2, c1)) {
+ if (d1 > d2) {
return 1;
}
return 0;