title: Making a JList scroll to the end of it's elements
body: <p>I am using the following code to scroll to the end of a JList. I use it when I setVisible on the window containing the JList and when I add items to the JList.</p>
  
  <pre><code>int lastIndex = getMyList().getModel().getSize() - 1;
  
  if (lastIndex &gt;= 0) {
      getMyList().ensureIndexIsVisible(lastIndex);
  }
  </code></pre>
  
  <p>The problem is that upon calling setVisible for the first time the JList scrolls up a couple of items for no apparent reason. If I then call setVisible(false) followed by a call to setVisible(true) the JList gets scrolled to the bottom like it is supposed to be. One thing I noticed was that the moment I open a window some of it's components seem to get re-arranged in a fraction of a second. So Im guessing the problem could be down to that.</p>
  
  <p>So I pressed 'print screen' when I opened one of these windows and you can see that when the window is initially opened the components at the bottom of it aren't even visible (the emoticons and the buttons). Here's what the window looks like when it is 'fully open', and also and image of what it looks like for a fraction of a second just before it is fully open.</p>
  
  <p><strong>How the window looks once it is opened (you can see the scrollbar is not at the bottom)</strong>
  <img src="https://i.stack.imgur.com/IlW5l.png" alt="enter image description here"></p>
  
  <p><strong>How the window looks when I screenshot it as it is opening after a call to setVisible()</strong>
  <img src="https://i.stack.imgur.com/zonUA.png" alt="enter image description here"></p>
  
  <p>So anyone know why the layout is changing as the window is opening and how I can get my JList to scroll to the bottom when it first opens?</p>