2

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.

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
Lion_CH
  • 78
  • 2
  • 8
  • There is no css property for this, see https://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#gridpane – fabian Mar 03 '16 at 14:20

1 Answers1

4

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.

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Going with the child nodes - as james suggested - would be the best way to go imho. If you really wanted to use css for your row constraint height properties, you would have to extend RowConstraints and add style sheet property handling to it. The imo easiest way to learn how to do that would be to look at how "official" javafx controls do it (e.g. Labeled class line 800 onwards) – JohnRW Mar 04 '16 at 08:29