return baseline;
}
@Override
public void layout() {
BoxPane boxPane = (BoxPane)getComponent();
int n = boxPane.getLength();
int width = getWidth();
int height = getHeight();
Orientation orientation = boxPane.getOrientation();
if (orientation == Orientation.HORIZONTAL) {
int preferredWidth = getPreferredWidth(fill ? height : -1);
// Determine the starting x-coordinate
int x = 0;
switch (horizontalAlignment) {
case CENTER: {
x = (width - preferredWidth) / 2;
break;
}
case RIGHT: {
x = width - preferredWidth;
break;
}
case LEFT: {
break;
}
default: {
break;
}
}
x += padding.left;
// Lay out the components
for (int i = 0; i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
int componentWidth = 0;
int componentHeight = 0;
int y = 0;
if (fill) {
componentHeight = Math.max(height - (padding.top
+ padding.bottom), 0);
componentWidth = component.getPreferredWidth(componentHeight);
} else {
Dimensions preferredComponentSize = component.getPreferredSize();
componentWidth = preferredComponentSize.width;
componentHeight = preferredComponentSize.height;
}
switch (verticalAlignment) {
case TOP: {
y = padding.top;
break;
}
case CENTER: {
y = (height - componentHeight) / 2;
break;
}
case BOTTOM: {
y = height - padding.bottom - componentHeight;
break;
}
default: {
break;
}
}
// Set the component's size and position
component.setSize(componentWidth, componentHeight);
component.setLocation(x, y);
// Increment the x-coordinate
x += componentWidth + spacing;
}
}
} else {
int preferredHeight = getPreferredHeight(fill ? width : -1);
// Determine the starting y-coordinate
int y = 0;
switch (verticalAlignment) {
case CENTER: {
y = (height - preferredHeight) / 2;
break;
}
case BOTTOM: {
y = height - preferredHeight;
break;
}
case TOP:
break;
default: {
break;
}
}
y += padding.top;
// Lay out the components
for (int i = 0; i < n; i++) {
Component component = boxPane.get(i);
if (component.isVisible()) {
int componentWidth = 0;
int componentHeight = 0;
int x = 0;