Reputation: 195
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
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