JTable refreshing

本小妞迷上赌 提交于 2019-12-24 09:49:27

问题


I use JTable with horizontal and vertical scrollbars. My JTable has empty space after rows with data. When I open panel that is situated down of my table it hides a part of JTable and scrolling appears on JTable. This is normal behavior, but then I close that panel, empty space without data becomes grey instead of white color. This only happens when I have horizontal scrollbar on my JTable. I suppose I must force JTable to repaint, I tried resizeAndRepaint() on TableHeader and JTable but it didn't work.

Please help! Thanks! Here is resize() code invoked if any resize action was performed on table

for (int i = 0; i < columsNum; i++){
        TableColumn column = this.getColumnModel().getColumn(i);
        int preferedSize = //current size
        int minimumSize = // min size
        if (minimumSize != ColumnSizeCalculator.UNDEFINED_WIDTH)
            column.setMinWidth(minimumSize);            
        column.setPreferredWidth(preferedSize);        
    }   

    this.revalidate();
    this.repaint();

回答1:


By default, a JTable does not fill the viewport of a scrollpane in the vertical direction. Try to call

table.setFillsViewportHeight(true);

on your table, then repainting the table should work.



来源:https://stackoverflow.com/questions/7736273/jtable-refreshing

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