GridLayout : adding and removing columns

The
GridLayout
component allows
rows
to be added and removed using the
insertRow()
and
removeRow()
methods. However, there are
no
similar
insertColumn()
and
removeColumn()
methods for
columns
.

This is causing me a problem because I need to update a large grid in real time, possibly involving adding/removing columns. And I want to avoid re-rendering the whole grid because it takes quite a long time.

[1]
Is there a reason why these methods are missing ?
[2]
If not, can I add these methods by hacking the GridLayout source code ?
[3]
If these methods can’t be added, is there a work around I can use to achieve the same effect ?


Update
:

I’ve tried adding the
insertColumn()
and
removeColumn()
methods to the
GridLayout
class by copy/pasting from the existing methods for rows. So far they
seem
to work OK :D:

    public void insertColumn(int col) {
        if (col > cols) {
            throw new IllegalArgumentException("Cannot insert col at " + col
                    + " in a gridlayout with width " + cols);
        }

        for (Iterator<Area> i = areas.iterator(); i.hasNext();) {
            Area existingArea = i.next();
            // Areas ending below the col needs to be moved down or stretched
            if (existingArea.column2 >= col) {
                existingArea.column2++;

                // Stretch areas that span over the selected col
                if (existingArea.column1 >= col) {
                    existingArea.column1++;
                }
            }
        }

        if (cursorX >= col) {
            cursorX++;
        }

        setColumns(cols + 1);
        structuralChange = true;
        requestRepaint();
    }

and

    public void removeColumn(int col) {
        if (col >= cols) {
            throw new IllegalArgumentException("Cannot delete col " + col
                    + " from a gridlayout with width " + cols);
        }

        // Remove all components in col
        for (int row = 0; row < getRows(); row++) {
            removeComponent(col, row);
        }

        // Shrink or remove areas in the selected col
        for (Iterator<Area> i = areas.iterator(); i.hasNext();) {
            Area existingArea = i.next();
            if (existingArea.column2 >= col) {
                existingArea.column2--;

                if (existingArea.column1 > col) {
                    existingArea.column1--;
                }
            }
        }

        if (cols == 1) {
            /*
             * Removing the last col means that the dimensions of the Grid
             * layout will be truncated to 1 empty col and the cursor is moved
             * to the first cell
             */
            cursorX = 0;
            cursorY = 0;
        } else {
            setColumns(cols - 1);
            if (cursorX > col) {
                cursorX--;
            }
        }

        structuralChange = true;
        requestRepaint();
    }

I’m also in need of the insertColumn function.

did you create a ticket for this?

There doesn’t seem to be an existing ticket for this, just the ancient
#124 for insertRow()/removeEmptyRow()
. I have no idea why the equivalent methods were not implemented for columns.

But now there is, created
#7226
.