cssjavafxgridpane

Apply css style to gridpane row


I'm using GridPane in JavaFx, I want to set the min height of all rows to 30. I know how to change the row constraint dynamically from code. But I want to do it from css, in order to apply it for all GridPanes.


Solution

  • Depending on the content of the grid pane, and on exactly what you want to do, it might work to do

    .grid-pane > * {
        -fx-min-height: 30 ;
    }
    

    Note that GridPane has no style class by default, so you will have to manually add the style class to it for this to work.

    This isn't quite the functionality you asked for. What this will actually do is set the -fx-min-height property on all immediate child nodes of the grid pane to 30. So as long as that node has such a property (i.e. as long as the child nodes are subclasses of Region), each of the nodes will have a minimum height of 30 pixels. This of course forces each row to be at least 30 pixels high, but depending on what you're placing in the grid pane, the overall effect might not be the same as setting the row constraints.