title: Java: JComboBox selection issue on image
body: <p>In this GUI there are four images which place on array of <code>DefaultComboBoxModel</code> and label which helps to display the image. The default image is <code>1.png</code> which appear on the frame. But when I select the other image from the combo list then it doesn't appear.</p>
  
  <h3>Code</h3>
  
  <pre><code>public class Combo extends JFrame {
  
      public Combo() {
          super("Combo 2 GUI");
  
          setSize(400, 300);
          MethodG();
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setLocationRelativeTo(null);
          setVisible(true);
      }
  
      private void MethodG() {
  
          JLabel l1;
          JComboBox box;
          JPanel p;
  
          Container pane = getContentPane();
  
          p = new JPanel();
  
          box = new JComboBox();
          box.setModel(new DefaultComboBoxModel(new String[] { "1.png", "2.png", "3.png", "4.png" }));
          box.setMaximumRowCount(3);
  
          String boxoption = (String) box.getSelectedItem();
  
          Icon[] icons = { new ImageIcon(getClass().getResource(boxoption)) };
  
          // Default display
          l1 = new JLabel(icons[0]);
  
          box.addItemListener(new ItemListener() {
  
              @Override
              public void itemStateChanged(ItemEvent e) {
                  if (e.getStateChange() == ItemEvent.SELECTED) {
  
                      l1.setIcon(icons[box.getSelectedIndex()]);
  
                  }
  
              }
  
          });
  
          pane.add(p);
  
          p.add(box);
          p.add(l1);
  
      }
  }
  </code></pre>
  
  <h3>Main method</h3>
  
  <pre><code>public class Main {
  
      public static void main(String[] args) {
  
          Combo obj = new Combo();
      }
  }
  </code></pre>
  
  <p>And the second problem what does these two lines do and how to write in if syntax.</p>
  
  <pre><code>JComboBox schemaBox;
  String schema = (schemaBox.isEnabled() ? schemaBox.getSelectedItem().toString() : null);
  String selectTable = (schema == null ? "" : schema + ".") + tableName;
  </code></pre>