atlantafx
atlantafx copied to clipboard
How to set background color for selected but not focused table row?
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:
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:
Could anyone say how to do it with atlantafx?