title: JTabbedPane ChangeListener
body: <p>I need to detect when the selected tab changes, and get its index.</p>
  <p>The following code works, but it fires the <code>println</code> as many times as the amount of tabs currently loaded:</p>
  <pre><code>tabbedPane.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
          System.out.println(&quot;Tab: &quot; + tabbedPane.getSelectedIndex());
          // Prints the string 3 times if there are 3 tabs etc
      }
  });
  </code></pre>
  <p>What is the correct way of doing this?</p>