Hey guys I am trying to do a scorelist for a Jump&Run game for a project in university I am saving the data of a Player
class with the attributes nickname
and finalScore
in an ArrayList
. I want to show the data in a FXML TableView
but it won't work and only shows no content.
I have already tried to declare the attributes as SimpleString
/IntegerProperty
s but it did not change.
public class ScoreController implements Initializable {
@FXML
private TableView<Player> table;
@FXML
private TableColumn<Player, String> Nickname;
@FXML
private TableColumn<Player, Integer> Score;
// Creating Observable Array List
private ObservableList<Player> data = FXCollections.observableArrayList();
// Set up the Scene
private Parent scoreList;
void setUp() throws Exception{
scoreList = FXMLLoader.load(getClass().getResource("/fxml/Score.fxml"));
App.scoreList = new Scene(scoreList,800,500);
}
// Adding data to the Observable List and setting Column Factories
@Override
public void initialize(URL url, ResourceBundle rb) {
data.add(new Player("Chris", 11));
data.add(new Player("Agil", 12));
Nickname.setCellValueFactory(new PropertyValueFactory<Player, String>("nickname"));
Score.setCellValueFactory(new PropertyValueFactory<Player, Integer>("finaleScore"));
table.setItems(data);
}
}
I expected the TableColumn to show the data of the ArrayList
but the TableView
only shows 'no content' in this table.
EDIT Player class
public Player(String nickname, int finalScore){
setNickname(nickname);
setFinalScore(finalScore);
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
void setFinalScore(int score){
finalScore = score;
}
public String getNickname(){
return nickname;
}
public int getFinalScore() {
return finalScore;
}