JavaFX TableView 换行文本选中行文本颜色

JavaFX TableView wrapped text selected row text color

我使用 Whosebug 将文本包装在 table 单元格中。但是当我关注 table 行时,文本颜色不再改变。我什么都试过了。

这是我控制器中现在的内容:

       colWie.setCellFactory(column -> {
        return new TableCell<DraaiboekActie, String>() {
            private Text text;

            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                if (!isEmpty()) {
                    text = new Text(item);
                    text.wrappingWidthProperty().bind(colWie.widthProperty());
                    text.getStyleClass().add("coltext");
                    setGraphic(text);
                    }
               }
           };
       });

这就是我 css 中的内容:

.coltext {
-fx-fill: white;
}

.coltext:focused:selected:filled{
-fx-fill: black;
}

你需要这样的东西

.table-cell .coltext {
    -fx-fill: white ;
}

.table-cell:focused:filled:selected .coltext {
    -fx-fill: black ;
}

(我假设 coltextdraaiboektext 应该是同一回事。)