Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX Generalize GridPane Column Constraints

Is there any way of apply a column constraint to all my GridPanes columns. I have various GridPane controls and I would like them to share the following column constraint:

<ColumnConstraints hgrow="SOMETIMES" maxWidth="388.0" minWidth="74.0" prefWidth="74.0" />

Could it be done using css?

Edit

I ended up doing something like this. But it does not work (my columns width get resized below 74), any clue ?

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());
        }
    }
}
like image 330
nailujed Avatar asked Nov 13 '22 19:11

nailujed


1 Answers

In your java controller code, loop through the columns and set whatever values you need.

like image 164
Andy Till Avatar answered Nov 15 '22 12:11

Andy Till