私には大きな問題があります。
TableView の TableColumn のコンテンツを中央に配置しようとしています。
ネットで見つけたものはすべて試しましたが、実際には何も機能しませんでした。
同じ問題を抱えている/持っている人はいますか? 解決策はありますか?
助けてください!
編集:
さて、私はこのコードで静的セルのコンテンツを中央に配置することができました:
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;
}
});
しかし、コンテンツはデータベースから取得する必要があり、メソッドで使用する ObservableList オブジェクトからデータを取得する方法が本当にわかりませんTABLEVIEWNAME.setItems
...
私は最初にこのコードを使用しました:
tc_customer.setCellValueFactory(new PropertyValueFactory<TvAccounting, String>("Customer"));
しかし、そのコンテンツを中央に配置する方法はありませんでした!
誰か助けてください。
編集:
この偉大な答えのおかげで、私はそれをやった!
以下のコード:
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"));
最高の感謝!!!