MaterialFX
MaterialFX copied to clipboard
MFXTableView - wrap text in cell and/or change cell height
Hi, I'm trying to create a table where a Description column is quite lengthy. I've tried the following:
public class LabelTableRow<T extends MyObject, E> extends MFXTableRowCell<T, E> {
public LabelTableRow(Function<T, E> extractor) {
super(extractor);
setWrapText(true); //does not have any effect
}
public void update(T item) {
super.update(item);
Label selected = new Label();
selected.setText(item.getDescription());
selected.setWrapText(true); // it wraps text inside the label, but not the wider cell
selected.setPrefWidth(300);
setGraphic(selected);
}
}
Is there a way to expand the height of the cell to accomodate higher elements?
The only way is to increase the height of all cells The current VirtualFlow doesn't support cells with variable height
I've tried that already, but it doesn't work either. Am I missing something? I've increase the hight at cell level. Is there a global property I've missed?
I also stuck trying to make it work. I tried to wrap the cell text such a way though
final MFXTableColumn<Model> descriptionColumn = new MFXTableColumn<>("Description");
descriptionColumn.setRowCellFactory(model -> {
final MFXTableRowCell<Model, String> cell = new MFXTableRowCell<>(Model::getDescription);
cell.setWrapText(true);
return cell;
});
descriptionColumn.prefWidthProperty().bind(dataGrid.widthProperty().multiply(0.2));
what I didn't know that VirtualFlow
doesn't support this.
Partially can be fixed if the row height is permanently increased
final Function<Model, MFXTableRow<Model>> dataGridRowFactory = dataGrid.getTableRowFactory();
dataGrid.setTableRowFactory(dataGridRowFactory .andThen(tableRow -> {
tableRow.setPrefHeight(300); <- this overrides the row height that is 32.0 by default | MFXTableRow.java:75
return tableRow;
}));
but of course this is ugly because the height should be dynamic based on the demand of the parent nodes.
Do I understand correctly that column name wrapping doesn't work because of the same reason? What I tried is
final MFXTableColumn<Model> postalCodeColumn = new MFXTableColumn<>("Postal code test long header");
postalCodeColumn.setRowCellFactory(model-> new MFXTableRowCell<>(Model::getPostalCode));
postalCodeColumn.setWrapText(true);
postalCodeColumn.setMaxWidth(50);
postalCodeColumn.setMinWidth(Region.USE_PREF_SIZE);
postalCodeColumn.setPrefWidth(50);
Header text is not wrapped even if the height of the header row is permanently increased
postalCodeColumn.setMinHeight(100);