// Include padding in constraint
if (height != -1) {
height = Math.max(height - (padding.top + padding.bottom), 0);
}
FlowPane flowPane = (FlowPane)getComponent();
int n = flowPane.getLength();
Orientation orientation = flowPane.getOrientation();
if (orientation == Orientation.HORIZONTAL) {
// Preferred width is the sum of the preferred widths of all
// components, plus spacing
int displayableComponentCount = 0;
for (int i = 0; i < n; i++) {
Component component = flowPane.get(i);
if (component.isDisplayable()) {
preferredWidth += component.getPreferredWidth(height);
displayableComponentCount++;
}
}
if (displayableComponentCount > 1) {
preferredWidth += spacing * (displayableComponentCount - 1);
}
} else {
// Preferred width is the maximum preferred width of all components
int maxComponentWidth = 0;
// Determine the fixed and total preferred heights, if necessary
int totalSpacing = 0;
int totalPreferredHeight = 0;
if (horizontalAlignment == HorizontalAlignment.JUSTIFY
&& height != -1) {
int displayableComponentCount = 0;
for (int i = 0; i < n; i++) {
Component component = flowPane.get(i);
if (component.isDisplayable()) {
totalPreferredHeight += component.getPreferredHeight(-1);
displayableComponentCount++;
}
}
if (displayableComponentCount > 1) {
totalSpacing = spacing * (displayableComponentCount - 1);
}
}
for (int i = 0; i < n; i++) {
Component component = flowPane.get(i);
if (component.isDisplayable()) {
int componentHeight = -1;
if (verticalAlignment == VerticalAlignment.JUSTIFY