javalistjavafxcollectionscontrolsfx

How to iterate values from List<String> in setCellValue method of GridBase in spreadsheet controlsfx?


i tried doing this

List<String> values = new ArrayList<>();
values.add("test1");
values.add("test2");
values.add("test3");
values.add("test4");
values.add("test5");

for(String e : values) {
    for (int column = 0; column < 30; column++){
        mGrid.setCellValue(10, column, e);
    }
}

But the only value that is being displayed in the cells is the last value which is "test5".

I also tried displaying the values through the console and it worked fine. Help me plz


Solution

  • You need to iterate the values and columns together with something like, so instead of:

            for(String e : values) {
                for (int column = 0; column < 30; column++){
                    mGrid.setCellValue(10, column, e);
                }
            }
    

    use something like:

            for (int column = 0; column < values.length; column++)
                mGrid.setCellValue(10, column, values.get(column));