title: JCombobox, object changed only on second click (ItemListener)
body: <p>i've some issue using listener to <code>JCombobox</code>.
  I have <code>JCombobox</code> with two <code>CercleItemOption</code> which is a composition of a <code>JLabel</code> and an object <code>CercleSelection</code> extending from <code>JPanel</code>. <code>CercleSelection</code> draws a circle with certain color. </p>
  
  <p>So i'm using <code>ItemListener</code> to support the event. My goal is to print on frame the colored circle corresponding to the selected item.</p>
  
  <pre class="lang-java prettyprint-override"><code>import javax.swing.*;
  import javax.swing.border.CompoundBorder;
  import javax.swing.border.EmptyBorder;
  import javax.swing.border.LineBorder;
  import java.awt.*;
  
  public class PanneauSelection extends JPanel {
  
      private GridBagConstraints grid = new GridBagConstraints();
  
      public PanneauSelection(){
          super();
          init();
          setVisible(true);
      }
  
      private void init() {
  
          LineBorder lb;
          CompoundBorder cb;
  
          setLayout(new GridBagLayout());
          EmptyBorder eb = new EmptyBorder(5,10,5,10);
  
          grid.fill = GridBagConstraints.BOTH;
          grid.insets = new Insets(3,3,3,3);
  
          JLabel[] appLabel = {
                  new JLabel("&lt;html&gt;Racc. &lt;br/&gt;Bac/conduite&lt;/html&gt;", SwingConstants.CENTER),
                  new JLabel("Vanne", SwingConstants.CENTER),
                  new JLabel("Pompe", SwingConstants.CENTER),
                  new JLabel("Turbine", SwingConstants.CENTER),
          };
  
          CercleSelection[] appCircle = {
                  new CercleSelection(new Color(222, 146, 15)),
                  new CercleSelection(Color.BLUE),
                  new CercleSelection(new Color(67, 160, 53)),
                  new CercleSelection(Color.RED),
          };
  
          DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
          dlcr.setHorizontalAlignment(DefaultListCellRenderer.CENTER);
  
          JComboBox&lt;CercleItemOption&gt; optionList = new JComboBox&lt;&gt;();
          optionList.addItem(new CercleItemOption(new JLabel("Coude"), new CercleSelection(Color.cyan)));
          optionList.addItem(new CercleItemOption(new JLabel("Chgt de section"), new CercleSelection(Color.PINK)));
          optionList.setRenderer(dlcr);
  
  
          for(int i=0; i&lt;appLabel.length; i++){
              grid.gridy = i;
  
              //First column
              grid.gridx = 0;
              lb = new LineBorder(appCircle[i].getCouleur(), 2, true);
              cb = new CompoundBorder(lb,eb);
              appLabel[i].setBorder(cb);
              add(appLabel[i], grid);
  
              //Second column
              grid.gridx = 1;
              appCircle[i].setBorder(eb);
              add(appCircle[i], grid);
          }
  
          grid.gridy = 4;
          grid.gridx = 0;
          add(optionList, grid);
  
          grid.gridx = 1;
          add(((CercleItemOption)optionList.getSelectedItem()).getCercle(), grid);
  
          optionList.addItemListener(itemEvent -&gt; {
              setVisible(false);
              grid.gridx = 1;
              grid.gridy = 4;
              CercleItemOption cs = (CercleItemOption) itemEvent.getItem();
              add(cs.getCercle(), grid);
              revalidate();
              repaint();
              setVisible(true);
          });
  
  
          this.setBorder(new EmptyBorder(0,20,0,0));
      }
  
  
      public static void main(String[] args){
          JFrame f = new JFrame();
          f.add(new PanneauSelection());
          f.pack();
          f.setLocationRelativeTo(null);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setVisible(true);
  
      }
  
  }
  </code></pre>
  
  <p>I expected something like :<br/>
  "coude" -> [Circle] cyan <br/>
  "chgt de section" -> [Circle] pink</p>
  
  <p>With my code color doesn't change on the first call of ItemListener, but only on the second one. Finally on second click, i have : <br>
  "coude" -> [Circle] pink <br>
  "chgt de section" -> [Circle] cyan </p>
  
  <p><code>CercleItemOption</code> class</p>
  
  <pre class="lang-java prettyprint-override"><code>    import javax.swing.*;
  
      public class CercleItemOption {
          private JLabel label;
          private CercleSelection cercle;
  
          public CercleItemOption(JLabel l, CercleSelection c){
              label = l;
              cercle = c;
          }
  
          @Override
          public String toString(){
              return label.getText();
          }
  
          public JLabel getLabel() {
              return label;
          }
  
          public CercleSelection getCercle() {
              return cercle;
          }
      }
  </code></pre>
  
  <p><code>CercleSelection</code> class</p>
  
  <pre class="lang-java prettyprint-override"><code>import javax.swing.*;
  import java.awt.*;
  
  public class CercleSelection extends JPanel {
  
      public final static int TAILLE = 11;
  
      Color couleur;
  
      public CercleSelection(Color c){
          super();
          couleur = c;
          setSize(TAILLE,TAILLE);
          setVisible(true);
      }
  
      @Override
      protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.setColor(couleur);
          //Draw in the middle
          g.fillOval(TAILLE/2,TAILLE/2,TAILLE,TAILLE);
      }
  
      public Color getCouleur() {
          return couleur;
      }
  
  }
  
  </code></pre>
  
  <p>Thank you in advance for help</p>