2012-10-19 67 views
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()); 
     } 
    } 
} 

回答

1

在您的java控制器代碼中,遍歷列並設置所需的任何值。

+0

我該如何循環控制場景?我嘗試過使用getChildrenUnmodifiable(),但它只返回第一級兒童 – nailujed

+0

不是嗎?如果網格窗格中有其他容器,那麼這些容器應該以自己的方式處理它們自己的佈局。例如,即使在GridPane中,VBox也應該像VBox一樣工作。 –