My TableView consists of several columns and wraps the text with the following cellfactory:
private void setWrapCellFactory(TableColumn<CustomObject, String> table) {
table.setCellFactory(tablecol -> {
TableCell<CustomObject, String> cell = new TableCell<>();
Text text = new Text();
cell.setGraphic(text);
text.wrappingWidthProperty().bind(cell.widthProperty());
text.textProperty().bind(cell.itemProperty());
return cell;
});
}
This works perfectly for showing uneditable text.
The last column has to be editable and could span across several rows (not TableView rows). To prevent the ellips I would like to wrap the new edited text.
After hours of trying I still can't seem to get it working. I have the following code to edit my cell and a non-working attempt to wrap it.
Non-working method to wrap my edited text:
private void setWrapCellFactoryEditable(TableColumn<CustomObject, String> table) {
table.setCellFactory(tablecol -> {
TableCell<CustomObject, String> cell = new TextFieldTableCell<>(new DefaultStringConverter());
Text text = new Text();
text.setText(text.toString());
text.wrappingWidthProperty().bind(cell.widthProperty());
return cell;
});
}
The following code is the column setup:
feedbackCol.setCellValueFactory(ev -> new ReadOnlyStringWrapper(ev.getValue().getLastFeedback()));
setWrapCellFactoryEditable(feedbackCol);
feedbackCol.setOnEditCommit((CellEditEvent<CustomObject, String> ev) -> {
int id = ((CustomObject) ev.getTableView().getItems().get(
ev.getTablePosition().getRow())).getId();
dc.addTempFeedback(id, ev.getNewValue());
});
For the regular non-editable text I'm using a TableCell, for editable text I'm using a TextFieldTableCell. I don't know why the wrapping isn't working with editable cells.