有益な情報を省略せずに、できるだけ短くしたい。私は次のクラスを持っています:
public class Address{
StringProperty city = new SimpleStringProperty();
StringProperty street = new SimpleStringProperty();
//following the constructor, getters and setters
...
}
別のクラス Client があり、そのクラスには Address メンバーがあります
public class Client {
StringProperty name = new SimpleStringProperty();
StringProperty id = new SimpleStringProperty();
ObjectProperty<Address> address = new SimpleObjectProperty<>();
//following the constructor, getters and setters
...
}
そして、指定されたオブジェクトの Client クラスのメンバーと Address クラスの都市メンバーを 3 列に出力する必要がある TableView オブジェクトを含むコントローラーを備えた JavaFX インターフェイス。私のTableViewとTableColumnの定義は次のコードです
public class SettingsController {
TableColumn<Client, String> clientNameCol;
TableColumn<Client, String> clientEmailCol;
TableColumn<Client, String> clientCityCol;
private TableView<Client> clientSettingsTableView;
...
...
clientNameCol = new TableColumn<>("Name");
clientNameCol.setCellValueFactory(new PropertyValueFactory<Client, String>("name"));
clientEmailCol = new TableColumn<>("email");
clientEmailCol.setCellValueFactory(new PropertyValueFactory<Client, String>("email"));
clientCityCol = new TableColumn<>("City");
clientCityCol.setCellValueFactory(new PropertyValueFactory<Client, String>("city"));
clientSettingsTableView.setItems(clientData);
clientSettingsTableView.getColumns().clear();
clientSettingsTableView.getColumns().addAll(clientNameCol, clientEmailCol, clientCityCol);
そしてもちろん、Client オブジェクトの配列を含む ObservableList clientData があります。各クライアントの都市を出力する必要がある列を除いて、すべてが正常に機能します。Client オブジェクトの都市 (Address メンバーに含まれる) の列を定義するにはどうすればよいですか?