I have a big Problem.
I try to center the Content of a TableColumn in a TableView.
I already tried everything I found on the net but really nothing of that worked!
Is anyone there who had/has the same problem? any Solutions?
Hope for help!
Edit:
Well I was able to center the content of a static cell with this code:
tc_customer.setCellFactory(new Callback<TableColumn<TvAccounting, String>, TableCell<TvAccounting, String>>() {
@Override
public TableCell<TvAccounting, String> call(TableColumn<TvAccounting, String> p) {
TableCell<TvAccounting, String> tc = new TableCell<TvAccounting, String>();
tc.setAlignment(Pos.CENTER);
tc.setText("SOMETEXT");
return tc;
}
});
But the content should come from a database and i really hav no idea how to get the data from the ObservableList Object that i use in the TABLEVIEWNAME.setItems
method...
I first used this code:
tc_customer.setCellValueFactory(new PropertyValueFactory<TvAccounting, String>("Customer"));
but there was no way to center that content!
Please could anyone help me?
Edit:
Thanks to this Great Answer, I did it!
Code below:
tc_customer.setCellFactory(new Callback<TableColumn<TvAccounting, String>, TableCell<TvAccounting, String>>() {
@Override
public TableCell<TvAccounting, String> call(TableColumn<TvAccounting, String> p) {
TableCell<TvAccounting, String> tc = new TableCell<TvAccounting, String>(){
@Override
public void updateItem(String item, boolean empty) {
if (item != null){
setText(item);
}
}
};
tc.setAlignment(Pos.CENTER);
return tc;
}
});
tc_customer.setCellValueFactory(new PropertyValueFactory<TvAccounting, String>("Customer"));
BEST THANKS!!!