我有一个大问题。
我尝试将 TableColumn 的内容居中放置在 TableView 中。
我已经尝试了我在网上找到的所有东西,但实际上没有任何效果!
有没有人遇到/有同样的问题?任何解决方案?
希望得到帮助!
编辑:
好吧,我能够使用以下代码将静态单元格的内容居中:
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;
}
});
Run Code Online (Sandbox Code Playgroud)
但是内容应该来自数据库,我真的不知道如何从我在TABLEVIEWNAME.setItems方法中使用的 ObservableList 对象中获取数据......
我第一次使用这个代码:
tc_customer.setCellValueFactory(new PropertyValueFactory<TvAccounting, String>("Customer"));
Run Code Online (Sandbox Code Playgroud)
但是没有办法让这些内容居中!
请问有人可以帮我吗?
编辑:
感谢这个伟大的答案,我做到了!
代码如下:
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) …Run Code Online (Sandbox Code Playgroud)