gridPane.setStyle("-fx-background-color: #C0C0C0;");
Works and sets the background color of the whole gridpane, but how do I set it for a certain row, eg. row 5?
Do I need to use stylesheets for this? I'd prefer to do it in Java.
EDIT: each row contains a label, but the label does not cover the whole row in a pane. If I could set the label to cover the whole row and then set the background color of the label that would be a workaround.
You can set the text color with -fx-text-fill and the background color with -fx-background-color . GridPane. setFillHeight(myStackPane, true); GridPane. setFillWidth(myStackPane, true);
GridPane lays out its children within a flexible grid of rows and columns. If a border and/or padding is set, then its content will be layed out within those insets. A child may be placed anywhere within the grid and may span multiple rows/columns.
add(button6, 2, 1, 1, 1); The first parameter of the add() method is the component (node) to add to the GridPane . The second and third parameter of the add() method is the column index and row index of the cell in which the component should be displayed. Column and row indexes start from 0.
If we use Grid Pane in our application, all the nodes that are added to it are arranged in a way that they form a grid of rows and columns.
you can add to each grid cell new Pane() object and set background to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With