我想尽可能简短而不省略有用的信息。我有以下课程:
public class Address{
StringProperty city = new SimpleStringProperty();
StringProperty street = new SimpleStringProperty();
//following the constructor, getters and setters
...
}
我有另一个班级客户,那个有一个地址成员
public class Client {
StringProperty name = new SimpleStringProperty();
StringProperty id = new SimpleStringProperty();
ObjectProperty<Address> address = new SimpleObjectProperty<>();
//following the constructor, getters and setters
...
}
和一个带有控制器的 JavaFX 接口,该控制器包含一个 TableView 对象,该对象应在 3 列中输出给定对象的 Client 类的成员和 Address 类的 city 成员。我的 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);
当然还有一个 ObservableList clientData 包含一个 Client 对象数组。一切正常,除了应该为每个客户输出城市的列。我应该如何定义客户对象的城市列(由地址成员包含)?