java.lang.UnsupportedOperationException from Grid

I’m getting this below exception

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

.remove(grid.getColumns().size() - 1);

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?

I need the ID column to displayFirst

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


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.remove(columnList.size() - 1);
columnList.add(0, rowIndex);

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


Yes, the first wasn’t a copy