java.lang.UnsupportedOperationException from Grid

I’m getting this below exception

Caused by: java.lang.UnsupportedOperationException
    at java.base/java.util.Collections$UnmodifiableList.add(Collections.java:1352)
``` and is caused by lines

grid.getColumns()
.remove(grid.getColumns().size() - 1);
grid.getColumns()
.add(0,rowIndex);


My objective is to move the last column to the first column. I see ``setColumnOrder`` method is available to reorder the columns but it needs individual columns. I do not want to create the columns manually and later add it to ``setColumnOrder``. Please let me know how can I reorder the columns?
![image.png|3236x467](upload://jEYKwdkr6gJio2wrCVXbHs33WAD.png)

I need the ID column to displayFirst
image.png

In the docs, under Components > Grid > Column Reordering & Resizing, the code shows:

 grid.setColumnReorderingAllowed(true);

I figure if it allows DnD functions like this, then it should be allowable/possible to do it programmatically too. Unfortunately, the code example doesn’t show this.

You can’t modify the result of getColumns, the list is unmodifiable. You can use this list and create a copy in the order you want then call setColumnOrder

Let me try. And another question, when the list is unmodifiable, why there are remove/add methods?

The returned instance list is unmodifiable, that’s why there are add/remove methods (Java lists don’t notify on changes)

I created a copy like this ```final List<Grid.Column> columnList = grid.getColumns();
columnList.remove(columnList.size() - 1);
columnList.add(0, rowIndex);

    grid.setColumnOrder(columnList);```. But still getting the same exception. What am I doing wrong ?

I think is what you meant ```final List<Grid.Column> columnList = new ArrayList<>();
columnList.addAll(grid.getColumns());
columnList.remove(columnList.size() - 1);
columnList.add(0, rowIndex);

    grid.setColumnOrder(columnList);```. This one worked

image.png

Yes, the first wasn’t a copy