The Swing updates the UI related changes only once using the Event Dispatch Thread (EDT). The method
sp.getVerticalScrollBar().setValue(10); Does not update the UI. It is simply setting the value at 10. hence it is done immediately. The second method that add the text to the screen willbring the Scroll Pane down but this will not be done immediately. It will be done on the EDT. Hence when you run your code it will always run the setValue() method first and the setText() method later. Thus you will not see the effect of setValue().
The Solution would be to use SwingUtilities.invokeLater(). I have modified your code a little to make it more neater. Hope it help!!!