atlantafx icon indicating copy to clipboard operation
atlantafx copied to clipboard

How to set background color for selected but not focused table row?

Open PavelTurk opened this issue 9 months ago • 1 comments

I need to set background color for selected but not focused table row. This is my java code:

public class JavaFxTest10 extends Application {

    private static record Student (int id, int mark) {};

    private TableView<Student> students = new TableView<>(FXCollections.observableList(
            List.of(new Student(1, 3), new Student(2, 4), new Student(3, 5))));

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Application.setUserAgentStylesheet(new Dracula().getUserAgentStylesheet());
        var idColumn = new TableColumn<Student, Integer>("Id");
        idColumn.setCellValueFactory((data) ->  new ReadOnlyObjectWrapper<>(data.getValue().id()));
        var markColumn = new TableColumn<Student, Integer>("Mark");
        markColumn.setCellValueFactory((data) ->  new ReadOnlyObjectWrapper<>(data.getValue().mark()));
        students.getColumns().addAll(idColumn, markColumn);

        VBox root = new VBox(new TextField(), students);
        var scene = new Scene(root, 400, 300);
        var css= this.getClass().getResource("test10.css").toExternalForm();

        scene.getStylesheets().addAll(css);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

And CSS:

.table-view {
    -fx-selection-bar-non-focused: yellow;
}

This solution works if I use pure JavaFX:

Peek 2024-05-09 18-21

However, with atltantafx it doesn't work - once selected row has always the same color - it doesn't matter if it is focused or not:

Peek 2024-05-09 18-22

Could anyone say how to do it with atlantafx?

PavelTurk avatar May 09 '24 15:05 PavelTurk