开发者

JTable refreshing

开发者 https://www.devze.com 2023-04-12 15:37 出处:网络
I use JTable with horizontal and vertical scrollbars. My JTable has empty space after rows with data.

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();


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消