vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.79k stars 729 forks source link

GridLayout : Last row's/ column's expand ratio is set to 0, after setRows()/setColumns() execution #7834

Closed vaadin-bot closed 7 years ago

vaadin-bot commented 7 years ago

Originally by anasmi


When the setRows(number) is less that existing rows number, the expand ratio of the last row in the new GridLayout is set to 0, which makes it disappear, if others rows have had an expand ratio. The same situation with setColumns(number). In setRows method it occurs due to "for (int i = rows - 1; i < getRows(); i++).." check in for-loop while it's supposed to be "for (int i = rows; i < getRows(); i++)..."

Created support request with code : https://vaadin.com/pro/support#1433


Imported from https://dev.vaadin.com/ issue #20297

vaadin-bot commented 7 years ago

Originally by anasmi


When the setRows(number) is less that existing rows number, the expand ratio of the last row in the new GridLayout is set to 0, which makes it disappear, if others rows have had an expand ratio. The same situation with setColumns(number). In setRows method it occurs due to "for (int i = rows - 1; i < getRows(); i++).." check in for-loop while it's supposed to be "for (int i = rows; i < getRows(); i++)..."

The attached code within the ticket, where "BUG HERE" indicates the rows, which cause the problem : public void setRows(int rows) {

// The the param
if (rows < 1) {
    throw new IllegalArgumentException(
            "The number of columns and rows in the grid must be at least 1");
}

// In case of no change
if (getRows() == rows) {
    return;
}

// Checks for overlaps
if (getRows() > rows) {
    for (Entry<Connector, ChildComponentData> entry : getState().childData
            .entrySet()) {
        if (entry.getValue().row2 >= rows) {
            throw new OutOfBoundsException(new Area(entry.getValue(),
                    (Component) entry.getKey()));
        }
    }
}
// Forget expands for removed rows
if (rows < getRows()) {
    for (int i = rows - 1; i < getRows(); i++) {   <== BUG HERE, should be i=rows;
        rowExpandRatio.remove(i);
        getState().explicitRowRatios.remove(i);
    }
}

getState().rows = rows;

}

public void setColumns(int columns) {

// The the param
if (columns < 1) {
    throw new IllegalArgumentException(
            "The number of columns and rows in the grid must be at least 1");
}

// In case of no change
if (getColumns() == columns) {
    return;
}

// Checks for overlaps
if (getColumns() > columns) {
    for (Entry<Connector, ChildComponentData> entry : getState().childData
            .entrySet()) {
        if (entry.getValue().column2 >= columns) {
            throw new OutOfBoundsException(new Area(entry.getValue(),
                    (Component) entry.getKey()));
        }
    }
}

// Forget expands for removed columns
if (columns < getColumns()) {
    for (int i = columns - 1; i < getColumns(); i++) {   <== BUG HERE, should be i=columns;
        columnExpandRatio.remove(i);
        getState().explicitColRatios.remove(i);
    }
}

getState().columns = columns;

}

vaadin-bot commented 7 years ago

Originally by @Artur-


https://dev.vaadin.com/review/14586