I am doing some work with a table contained in a scroll pane. The function I am calling does an operation on the table and then redraws the table, which changes the position of the vertical scroll bar. I am trying to figure out a way to restore the scroll bar's initial position after the function. Here's a sample of what I have so far:
public void lineCopy(){
scrollPosition = jScrollPane1.getVerticalScrollBar().getValue;
//Main body of tableCopy function here, including call to
//getNewTable() which gets the new table
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
jScrollPane1.getVerticalScrollBar().setValue(scrollPosition);
System.out.println("Run Later Here");
}
});
System.out.println("End of copy function");
}
The problem is the scroll bar does not reset to the value it had before the function, it usually scrolls further down the window than before (for example, if line 200 was at the top of the window before the function, line 250 is at the top after).
Here's what I know: The invokeLater is indeed invoking later based on the system output lines I've added. Also I know that the setValue function is working because if I set it to setValue(0) instead of setValue(scrollPosition), it works every time.
Other info: I have tried similar code using getting/setting viewports and have got similar results. Also, some rows have different heights, based on the type of value in the row (matrix vs constant).
Thanks for the help