Skip to content
Advertisement

JavaFX – how to display values of two table columns in TableView with different order from one ObservableList?

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:

enter image description here

My current code for this is as follows:

JavaScript

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.

Advertisement

Answer

Each row in the table represents a match with two players, not a single Player. So the data type for your TableView needs to be a data type that represents two players.

E.g. define a record:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement