JScrollPane automagically scrolls down to lowest component in JPanel
<p>In my JPanel (which is in a JScrollPane) I have several JTextArea. When launching the program these areas are populated by JTextArea.setText("text");</p>

<p>The problem is that the JScrollPane scrolls down to the JTextArea with the lowest Y-position as if the user would have focus on the JTextArea, no matter when it was populated with text. I thought that I could work around the problem by populating the JTextArea at the bottom first, if the JScrollPane maybe want to scroll to the "current" JTextArea that's being used. It didn't work so I'm assuming it just remembers the lowest point it's been and then just stays there for some reason.</p>

<p>Setting the view like this doesn't make any difference.</p>

<pre><code>JScrollPane.getViewPort().scrollRectToVisible(new Rectangle(0,0,1,1));
</code></pre>

<p>I've tested by neglecting to populate the last JTextAreas and the JScrollPane is then viewing the top of the JPanel, as I want.
What's happening, and why is it ignoring my code?</p>

<p><strong><em>Update, answer selected</em></strong>
You have to set the viewport a tad later when the GUI is ready</p>

<pre><code>SwingUtilities.invokeLater(new Runnable() 
    {
        public void run() 
        {
            scrollPane.getViewport().setViewPosition(new Point(0, 0));
        }
    });
</code></pre>