int x = rollupButtonSize.width + buffer;
int y = 0;
int justifiedWidth = Math.max(getWidth() - rollupButtonSize.width - buffer, 0);
Component firstComponent = null;
for (int i = 0, n = rollup.getLength(); i < n; i++) {
Component component = rollup.get(i);
if (component == rollupButton) {
// Ignore "private" component
continue;
}
if (firstComponent == null) {
firstComponent = component;
}
if ((component == firstComponent
|| rollup.isExpanded())
&& component.isDisplayable()) {
// We lay this child out and make sure it's painted.
component.setVisible(true);
int componentWidth, componentHeight;
if (justify) {
componentWidth = justifiedWidth;
componentHeight = component.getPreferredHeight(componentWidth);
} else {
Dimensions componentPreferredSize = component.getPreferredSize();
componentWidth = componentPreferredSize.width;
componentHeight = componentPreferredSize.height;
}
component.setLocation(x, y);
component.setSize(componentWidth, componentHeight);
y += componentHeight + spacing;
} else {
// We make sure this child doesn't get painted. There's also
// no need to lay the child out.
component.setVisible(false);
}
}
int rollupButtonY = (firstComponent == null) ?
0 : (firstComponent.getHeight() - rollupButtonSize.height) / 2 + 1;