Ulkurz
Ulkurz

Reputation: 83

How to change the background color of the focussed table row

So I've a method that focuses the table row based on the row index. However, the default background color of the focused row is grey, which is not easily visible. I want to change this color to steelblue. Please suggest how to do it. Below is my code for the method.

public static void focusTableRow(TableView table, int rowIndex){
    table.requestFocus();
    table.getSelectionModel().select(rowIndex);
    table.getFocusModel().focus(rowIndex); 
    table.scrollTo(rowIndex);   
}

Upvotes: 0

Views: 404

Answers (1)

Kachna
Kachna

Reputation: 2961

To style the rows, Add CSS in the external CSS file :

.table-row-cell:selected {

        -fx-background: steelblue;

}

Update:

Save the content of this style in a rowStyles.css. then you have to add the URL for the rowStyles.css style sheet to the scene:

scene.getStylesheets().add(getClass().getResource("rowStyles.css").toExternalForm());

Upvotes: 1

Related Questions