Im working on a JavaFX project that has a TableView with a dynamic number or columns (ObservableList). I want to display the table horizontally so that the col titles are the begining of the row and all col values are in the row. See image below:
I've thought of rotating the whole table 90° and going into each cell individually and rotating 90° but am unsure how the TextFieldTableCell would behave doing that. Any help would be great, thanks!
public static void configureTable(TableView table, int cols) {
StringUtil util = new StringUtil();
for (int i = 0; i < cols; i++) {
final int j = i;
TableColumn col = new TableColumn(util.numberToLetter(i));
col.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<ObservableList, String>, ObservableValue<String>>() {
public ObservableValue<String> call(TableColumn.CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
col.setEditable(true);
col.setCellFactory(TextFieldTableCell.forTableColumn());
col.setOnEditCommit(
new EventHandler<TableColumn.CellEditEvent<ObservableList, String>>() {
@Override
public void handle(TableColumn.CellEditEvent<ObservableList, String> t) {
String input = t.getNewValue();
int rowNumber = t.getTablePosition().getRow();
ObservableList row = t.getRowValue();
row.set(j, input);
}
}
);
table.getColumns().addAll(col);
}
}