1 Reply Latest reply on Sep 4, 2013 6:27 PM by MoC

    How to set the background colour of a column or row in a grid pane?




      I have a dialog with a grid pane layout.  Can I set the background colour of individual columns or rows?





        • 1. Re: How to set the background colour of a column or row in a grid pane?

          Don't think you can. One trick is to place a styled region in the first cell of the column and and set its row span to remaining. Here's a little FXML mockup I made in Scene Builder.


          <?xml version="1.0" encoding="UTF-8"?>
          <?import java.lang.*?>
          <?import java.util.*?>
          <?import javafx.geometry.*?>
          <?import javafx.scene.control.*?>
          <?import javafx.scene.layout.*?>
          <?import javafx.scene.paint.*?>
          <GridPane style="-fx-border-color: black;" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/2.2">
              <Label text="Name" GridPane.columnIndex="0" GridPane.rowIndex="0">
                  <Insets left="5.0" fx:id="x1" />
              <Label text="Surname" GridPane.columnIndex="0" GridPane.margin="$x1" GridPane.rowIndex="1" />
              <Region prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: darkgrey;" GridPane.columnIndex="1" GridPane.rowIndex="0" GridPane.rowSpan="2147483647" />
              <TextField GridPane.columnIndex="1" GridPane.rowIndex="0">
                  <Insets bottom="5.0" left="5.0" right="5.0" top="5.0" fx:id="x2" />
              <TextField GridPane.columnIndex="1" GridPane.margin="$x2" GridPane.rowIndex="1" />
              <ColumnConstraints hgrow="SOMETIMES" maxWidth="99.0" minWidth="10.0" prefWidth="75.0" />
              <ColumnConstraints hgrow="SOMETIMES" maxWidth="129.0" minWidth="10.0" prefWidth="125.0" />
              <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
              <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />