我的 Javafx 应用程序中有一个 HBox,配置如下
HBox belowBox = new HBox(10);
belowBox.getStyleClass().addAll("pane", "vbox");
belowBox.setAlignment(Pos.CENTER);
belowBox.getChildren().addAll( .... );
belowBox.setMaxHeight(200);
belowBox.setPrefHeight(200);
belowBox.setFillHeight(false);
但是,如果我调整我的应用程序的大小,HBox 仍然会垂直增长。有没有办法固定高度。
谢谢
最佳答案
但这是 HBox 布局 Pane 的确切行为。如果您阅读 HBox documentation ,您将看到以下内容:
HBox lays out its children in a single horizontal row...
还有:
HBox will resize children (if resizable) to their preferred widths and uses its fillHeight property to determine whether to resize their heights to fill its own height or keep their heights to their preferred (fillHeight defaults to true)...
如前所述,如果出于某种原因您设置了 fillHeight HBox 的属性,您可以使包含在其中的节点填充空的垂直空间,但这只会发生在可调整大小的节点上。有关使用 JavaFX 布局面板的更多信息,请查看 here .如果我没记错的话,文本、几何形状和 ImageView 不是可调整大小的对象。
关于Javafx HBox 限制到特定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21213882/