return baseline;
}
@Override
public void layout() {
FillPane fillPane = (FillPane)getComponent();
// n is the number of 'visible' components
// len is the total number of components
int n = 0;
int len = fillPane.getLength();
for (int i = 0; i < len; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
n++;
}
}
int width = getWidth();
int height = getHeight();
if (width <= 0)
width = getPreferredWidth(-1);
if (height <= 0)
height = getPreferredHeight(-1);
Orientation orientation = fillPane.getOrientation();
if (orientation == Orientation.HORIZONTAL) {
// Determine the starting x-coordinate
int x = padding.left;
int totalWidth = width - (padding.left + padding.right);
if (n > 1)
totalWidth -= spacing * (n - 1);
int dividedWidth = n == 0 ? 0 : totalWidth / n;
int leftoverWidth = totalWidth - (dividedWidth * n);
// Lay out the components
for (int i = 0, j = 0; i < len; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
int componentWidth = dividedWidth;
if (j == n - 1)
componentWidth += leftoverWidth;
int componentHeight = Math.max(height - (padding.top
+ padding.bottom), 0);
int y = padding.top;
// Set the component's size and position
component.setSize(componentWidth, componentHeight);
component.setLocation(x, y);
// Increment the x-coordinate
x += componentWidth + spacing;
j++;
}
}
} else {
// Determine the starting y-coordinate
int y = padding.top;
int totalHeight = height - (padding.top + padding.bottom);
if (n > 1)
totalHeight -= spacing * (n - 1);
int dividedHeight = n == 0 ? 0 : totalHeight / n;
int leftoverHeight = totalHeight - (dividedHeight * n);
// Lay out the components
for (int i = 0, j = 0; i < len; i++) {
Component component = fillPane.get(i);
if (component.isVisible()) {
int componentHeight = dividedHeight;
if (j == n - 1)
componentHeight += leftoverHeight;