我正在尝试创建一个显示每个活动以及参与成员的表格视图。活动具有成员列表,而成员具有活动列表。我被困在显示活动名称和活动成员的列中。我想在每行上显示一个活动成员组合。我也不确定如何填充表格,因为我正在传递活动列表。
这就是我想要的。
+----------+------------+-------------+----------------+-------------+
| Activity | Type | Member name | Member surname | Member rank |
+----------+------------+-------------+----------------+-------------+
| act1 | Internship | Peter | Peterson | 1 |
| act1 | Internship | Bob | Bobber | 3 |
| act2 | Sport | Tim | Tom | 1 |
| act2 | Sport | Bob | Bobber | 3 |
+----------+------------+-------------+----------------+-------------+
public class ActivityListController extends GridPane {
@FXML
private TableView<Activity> tblActivities;
@FXML
private TableColumn<Activity, String> colActivityName;
@FXML
private TableColumn<Activity, String> colType;
@FXML
private TableColumn<Activity, List<String>> colFirstName;
@FXML
private TableColumn<Activity, String> colLastName;
@FXML
private TableColumn<Activity, String> colRank;
private final DomeinController dc;
public ActivityListController(DomainController dc) {
this.dc = dc;
FXMLLoader loader = new FXMLLoader(getClass().
getResource("ActivityList.fxml"));
loader.setController(this);
loader.setRoot(this);
try {
loader.load();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
colActivity.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getName()));
colActivy.setCellFactory(TextFieldTableCell.forTableColumn());
colFirstName.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getMembers().???));
colLastName.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getMembers().???));
colRank.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getMembers().???));
tblActivities.setItems(dc.getAllActivities());
}