I've got a tableview of floats which work fine. I've made it so the cells are editable, formatted for currency etc. All the cells are right-justified as one would expect a numerical field to be.
One of the columns references a string (instead of a float), which is also editable-- that works too, using the TextFieldTableCell.forTableColumn()
method.
However I can't figure out how to left-justify the string -- it is right justified like the other columns. I tried using the .setAlignment(Pos.CENTER_LEFT)
method, but it only left-justifies when the cell is being edited. After editing, it is right-justified again...
Here's the snippet for that particular column:
cargoTableTypeCol.setCellFactory((TableColumn<CargoItem, String> p) -> {
TableCell<CargoItem, String> cell = new TableCell<>();
cell.setAlignment(Pos.CENTER_LEFT);
return cell;
});
cargoTableTypeCol.setCellFactory(TextFieldTableCell.forTableColumn());
cargoTableTypeCol.setCellValueFactory(cellData -> cellData.getValue().typeProperty());
And here's what it looks like:
as you can see the cell with "coal" in it is not left-justified. Iknow it's trivial, but frustrating nonetheless.
I suggest you to try the following: cargoTableTypeCol.setStyle("-fx-alignment: CENTER-LEFT;");