Skip to content

Commit

Permalink
workaround/fix for JavaFX FlowPane bug of not wrapping children.
Browse files Browse the repository at this point in the history
Bug reported by Benjamin Peters (@dedeibel) see #163
N.B. in combination with StackPane (ie not managed), the FlowPane does
not automatically wrap the children. Forced the behaviour by explicitly
setting the width, height and preferred wrapping widht of the FlowPane.
Shape does not scale consistently (some Schmidt-trigger like behaviour
... intrinsic to JavaFX layout manager???)
At least it wraps now ... so we leave it at that.
  • Loading branch information
RalphSteinhagen committed Apr 24, 2020
1 parent 9bcf624 commit f4f06e1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions chartfx-chart/src/main/java/de/gsi/chart/ui/ToolBarFlowPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ public ToolBarFlowPane(final Chart chart) {
this.setMinHeight(0);

this.setShape(ToolBarShapeHelper.getToolBarShape(this.getWidth(), this.getHeight(), cornerRadius.get()));
this.setPrefWidth(USE_PREF_SIZE);


this.setAlignment(Pos.TOP_CENTER);
this.setMinWidth(0);
setPadding(calculateInsets()); // NOPMD
VBox.setVgrow(this, Priority.ALWAYS);
HBox.setHgrow(this, Priority.NEVER);

ChangeListener<Number> toolBarSizeListener = (ch, o, n) -> {
Expand All @@ -69,18 +68,20 @@ public ToolBarFlowPane(final Chart chart) {
}

private void adjustToolBarWidth() {
final double maxLength = 0.90 * chart.getCanvas().getWidth();
final double maxLength = 0.60 * chart.getWidth();
double length = 0.0;
for (Node node : this.getChildren()) {
length += node.prefWidth(DEFAULT_TOOLBAR_HEIGHT);
}
length += 4 * cornerRadius.get();
final double wrapLength = Math.min(maxLength, Math.max(length, 50));
this.setPrefWrapLength(wrapLength);
this.setMaxWidth(wrapLength);
this.setWidth(maxLength);
final int height = (int)Math.max(getHeight(), Math.max(getBoundsInParent().getHeight(), getBoundsInLocal().getHeight()));
this.setMinHeight(height);

this.prefWrapLengthProperty().set(wrapLength);
this.setMaxWidth(maxLength);
this.setWidth(length);
this.setShape(ToolBarShapeHelper.getToolBarShape(wrapLength, this.getHeight(), cornerRadius.get()));
this.setShape(ToolBarShapeHelper.getToolBarShape(wrapLength, height, cornerRadius.get()));
}

/**
Expand Down

0 comments on commit f4f06e1

Please sign in to comment.