3
有没有任何方法将列约束应用于我的所有GridPanes列。 我有不同的GridPane控制,我想他们分享以下列约束:JavaFX泛化GridPane列约束
<ColumnConstraints hgrow="SOMETIMES" maxWidth="388.0" minWidth="74.0" prefWidth="74.0" />
难道使用CSS来实现?
编辑
最后我做这样的事情。但它不起作用(我的列宽度调整到74以下),任何线索?
public static void resizeColumns(Pane parent){
for (Node component : parent.getChildren()) {
if (component instanceof GridPane) {
GridPane gridPane = (GridPane) component;
ObservableList<ColumnConstraints> columnConstraints = gridPane.getColumnConstraints();
for (ColumnConstraints column : columnConstraints) {
column.setMinWidth(74.0);
}
} else if (component instanceof Pane) {
resizeColumns((Pane) component);
} else if (component instanceof ScrollPane) {
resizeColumns((Pane) ((ScrollPane) component).getContent());
}
}
}
我该如何循环控制场景?我尝试过使用getChildrenUnmodifiable(),但它只返回第一级儿童 – nailujed
不是吗?如果网格窗格中有其他容器,那么这些容器应该以自己的方式处理它们自己的布局。例如,即使在GridPane中,VBox也应该像VBox一样工作。 –