JavaFX - 如何在 TableView 中以与一个 ObservableList 不同的顺序显示两个表列的值?
这里的大学生目前正在从事锦标赛应用程序项目,我遇到了 GUI 的当前问题:
我的匹配算法采用玩家的号码并将最低号码与最高号码进行匹配,例如,如果我们有 8 名玩家,那么我们将有; P1 与 P8、P2 与 P7 等等。我目前正在尝试使用两列在 TableView 中显示它。这意味着同一行上第一列需要显示 P1,第二列需要显示 P8。遗憾的是,我无法弄清楚如何进行这项工作,因为当前的代码将玩家堆叠在一起,如下所示:
我当前的代码如下:
@FXML
private void initialize() {
playerViewer.setPlaceholder(new Label("Players will be shown here"));
SingleElimTournament tournament = new SingleElimTournament();
for(int i = 1; i < 9; i++) {
tournament.addPlayer(new Player("Player " + i, i));
}
int start = 0; //The id for first player according to a seed
int end = tournament.getPlayerAmount() - 1; //The id for last player according to a seed
while (start < end) {
playerList.add(tournament.getPlayersList().get(start));
playerList.add(tournament.getPlayersList().get(end));
start++; //Moving on to the next match
end--; //Moving on to the next match
}
columnOne.setCellValueFactory(new PropertyValueFactory<Player, String>("name"));
columnTwo.setCellValueFactory(new PropertyValueFactory<Player, String>("name"));
playerViewer.setItems(playerList);
}
我需要更改什么用于显示的列敌方球员并排而不是互相压在上面?非常感谢任何建议。
University student here currently working on a tournament application project, and I've got this current issue with GUI:
My matchmaking algorithm takes the player's numbers and matches the lowest number with the highest, for example if we have 8 players then we will have; P1 vs P8, P2 vs P7 and so on. I am currently trying to display this in a TableView using two columns. This means that column one needs to show P1, and column two needs to show P8 on the same row. I am sadly unable to figure out how to make this work, because the current code stacks the players on top of eachother like this:
My current code for this is as follows:
@FXML
private void initialize() {
playerViewer.setPlaceholder(new Label("Players will be shown here"));
SingleElimTournament tournament = new SingleElimTournament();
for(int i = 1; i < 9; i++) {
tournament.addPlayer(new Player("Player " + i, i));
}
int start = 0; //The id for first player according to a seed
int end = tournament.getPlayerAmount() - 1; //The id for last player according to a seed
while (start < end) {
playerList.add(tournament.getPlayersList().get(start));
playerList.add(tournament.getPlayersList().get(end));
start++; //Moving on to the next match
end--; //Moving on to the next match
}
columnOne.setCellValueFactory(new PropertyValueFactory<Player, String>("name"));
columnTwo.setCellValueFactory(new PropertyValueFactory<Player, String>("name"));
playerViewer.setItems(playerList);
}
What would I need to change for the columns to display the opposing players side-to-side instead of on top of eachother? Any advice is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表中的每一行代表两名玩家的比赛,而不是单个
玩家
。因此,TableView
的数据类型需要是代表两个玩家的数据类型。例如定义一个
记录
:Each row in the table represents a match with two players, not a single
Player
. So the data type for yourTableView
needs to be a data type that represents two players.E.g. define a
record
: