The only reason I can think of is because the view port position hasn't changed.
The first thing that comes to mind, is the view port may not have yet reacted to a change in position from the text begin set, so dumping the result immediately after you've set the text is reflecting the current state of the scroll bar (which has not yet begin updated)
You could try
SwingUtilities.invokeLater(new Runnable() {
public void run() {
System.out.println("Position: "+sf.query_scroll_pane.getHorizontalScrollBar().getValue());
}
});
instead and see if that prints out a more up-to-date value
Alternativly, you could add a AdjustmentListener
to the scroll bar, which will notify when changes occur JScrollBar#addAdjustmentListener