简体   繁体   中英

My loop only prints out one object to my tableview. I´m using Java

private void displayGroupsInRanking() {


    for (int i = 0; i < 4; i++) 

    {

        RankingANames.setItems(FXCollections.observableArrayList(groupModel.getListA().get(i).getName()));
        System.out.println(RankingANames);

    }
        RankingBNames.setItems(FXCollections.observableArrayList(groupModel.getListB()));
        RankingCNames.setItems(FXCollections.observableArrayList(groupModel.getListC()));
        RankingDNames.setItems(FXCollections.observableArrayList(groupModel.getListD()));


}

I´m trying to, to get a specific attribute from an arraylist into a new arraylist. This works fine, but the listview only shows one object? [The output 1

the Code

I'll not rewrite code from your screen to show you the right way to do this but I can tell you what is wrong here.

On every iteration you are creating new collection with exactly one item and then you are using it as items list for table. That's clearly wrong.

To solve it, you have to first prepare full list of items and then pass it to setItems method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM