Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting GridPane to have different background color in one row

Tags:

java

javafx-2

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.

like image 559
The Unfun Cat Avatar asked Aug 31 '12 16:08

The Unfun Cat


People also ask

How do I change the GridPane color in Javafx?

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);

What is a grid pane?

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.

How do I add things to GridPane?

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.

How the nodes in a grid pane are arranged?

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.


1 Answers

you can add to each grid cell new Pane() object and set background to it.

like image 104
V. Artyukhov Avatar answered Sep 29 '22 10:09

V. Artyukhov