Multipage JTable: impossible to display less items than rows

耗尽温柔 提交于 2019-12-02 09:05:59

Make sure your model's getRowCount method is inline with what you want it to do. The getRowCount method should return an acceptable number for your table, so that it doesn't call getValueAt for any rows that don't exist. So, if you have no row 14, your row count shouldn't be that high.

mKorbel

I think that not easy job, I suggessting to look at aephyr's code, maybe more easies way is implementing this code, but for real effect you have to lock JScrollBars, swith to NEVER

Just pin the the value to its acceptable maximum:

realRow = Math.min(realRow, getRowCount());

Addendum: In the example cited, implement getValueAt() as follows:

// Work only on the visible part of the table.
public Object getValueAt(int row, int col) {
    int realRow = row + (pageOffset * pageSize);
    if (realRow < data.length) {
        return data[realRow].getValueAt(col);
    } else {
        return null;
    }
}

Also consider BasicArrowButton.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!