以下场景:以下表格/列的行,具有长字符串值。我想出了如何通过手动调用“setCellFactory”并将“text.wrappingWidthProperty()”绑定到列的宽度来解决包装这些长字符串值的问题。
那工作正常。
这是我正在谈论的代码片段:
@FXML
private TableView<Row> tableEssen;
@FXML
private TableColumn<Row, String> columnEssen;
...
columnEssen.setCellFactory(new Callback<TableColumn<Row,String>, TableCell<Row,String>>() {
@Override
public TableCell<Row, String> call( TableColumn<Row, String> param) {
final TableCell<Row, String> cell = new TableCell<Row, String>() {
private Text text;
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (!isEmpty()) {
text = new Text(item.toString());
text.wrappingWidthProperty().bind(getTableColumn().widthProperty());
text.fontProperty().bind(fontProperty());
setGraphic(text);
}
}
};
return cell;
}
});
现在我的下一个小问题是,所选行的字体颜色是黑色 - 它应该是白色的。“Essen”列与 Text 类一起使用,“Preis”是一个简单的字符串。“Preis”列还可以,但“Essen”不行。我试过“text.fontProperty().bind(fontProperty());”,但这没有帮助。
有谁知道在选择行时如何获得正确的字体颜色?
编辑:问题解决了。
这里的字体略有不同:
左:没有 text.getStyleClass().addAll("table-text", "text");
右:与text.getStyleClass().addAll("table-text", "text");