I have the same problem as in JavaFX TableView text alignment, but old solution doesn't work with JavaFX 8. With code below, the cells are painted red, but alignment is still left. "-fx-text-alignment" doesn't work either.
main.fxml (relevant fragment)
<AggregatorTableView id="aggregators"/>
styles.css
#aggregators .table-cell {
-fx-alignment: CENTER-RIGHT;
-fx-background-color: red;
}
AggregatorTableView.java
public class AggregatorTableView extends TableView<Aggregator> {
public AggregatorTableView() {
TableColumn<Aggregator, Boolean> activeCol = new TableColumn<>("Active?");
TableColumn<Aggregator, String> nameCol = new TableColumn<>("Name");
TableColumn<Aggregator, String> resourceCol = new TableColumn<>("Resource");
TableColumn<Aggregator, String> versionCol = new TableColumn<>("Version");
activeCol.setCellValueFactory(cdf -> cdf.getValue().isActive());
activeCol.setCellFactory(CheckBoxTableCell.forTableColumn(activeCol));
activeCol.setOnEditCommit(e -> e.getRowValue().isActive().set(e.getNewValue()));
nameCol.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getName()));
resourceCol.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getResource()));
versionCol.setCellValueFactory(cdf -> new SimpleStringProperty(cdf.getValue().getVersion()));
getColumns().addAll(activeCol, nameCol, resourceCol, versionCol);
setEditable(true);
setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
getItems().add(new Aggregator() {
private BooleanProperty isActive = new SimpleBooleanProperty(true);
@Override public String getName() { return "test"; }
@Override public String getVersion() { return "0.0.1"; }
@Override public String getResource() { return "test.org"; }
@Override public List<DataItem> receiveData() { return null; }
@Override public BooleanProperty isActive() { return isActive; }
});
}
}