Nadeem
Nadeem

Reputation: 195

Refreshing the Jtable is scrolling the table

When I refresh the jtable data using custom refresh button, then the jtable scroll to a random position. The code I used is:

JscrollPane jsPane = new JscrollPane();
Jtable table = new JTable();
jsPane.setViewportView(table);
getContentPane().add(jsPane, java.awt.BorderLayout.CENTER);

I want jtable to maintain its viewport after refresh. how can I achieve this?

Upvotes: 0

Views: 938

Answers (1)

chipukb
chipukb

Reputation: 322

As kleopatra said, is very wierd. But still you can easily force:

int scrollPosition = scroll.getVerticalScrollBar().getValue();
try {
...do the update to the table...
} finally {
    scroll.getVerticalScrollBar().setValue(scrollPosition);
    }
}

Upvotes: 1

Related Questions