user1021712
user1021712

Reputation: 335

JTable in a JScrollPane doesn't automatically repaint when scrolling

I have a JScrollPane that holds a JTable. The table is dynamically populated from a database query. That all works fine and the table is getting populated, but its wider than the visible window.

I can see the left part of the table and I need to scroll right to see the right end of it. When I do that, the part of the table that was hidden (right end) is blurred. Then I stop scrolling and wait few seconds and then it is repainted and looks fine. I scroll back left and everything is OK - no blur.

Here is how I construct it (I wont paste all the code since it basically work):

    jScrollPane1.setAutoscrolls(true);
    jScrollPane1.getViewport().setLayout(borderLayout2);        
    jScrollPane1.getViewport().add(table, BorderLayout.CENTER);
    this.add(jScrollPane1, BorderLayout.CENTER);

Upvotes: 0

Views: 1635

Answers (1)

kleopatra
kleopatra

Reputation: 51536

Never seen such an artifact, might be due to the fact that you are adding the table in a completely wrong manner. Replace the first three lines of your snippet with:

jScrollPane1.setViewportView(table);

Upvotes: 3

Related Questions