title: Display Images in JFrame from JComboBox event
body: <p>I want to achieve following functionality :</p>
  
  <p>Eg :</p>
  
  <ul>
  <li>When user selects "Profile Pic"item from JComboBox releted images from "Profile Pic" folder should be loaded on same frame.</li>
  <li>Again when user selects "Product Img" item related images from "Product Img" folder should be loaded replacing previous images.</li>
  </ul>
  
  <p>Following is code snippet , please suggest any changes</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics2D;
  import java.awt.RenderingHints;
  import java.awt.event.ActionEvent;
  import java.awt.event.FocusAdapter;
  import java.awt.event.FocusEvent;
  import java.awt.event.KeyEvent;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.awt.image.BufferedImage;
  import java.net.URL;
  import java.util.ArrayList;
  import javax.imageio.ImageIO;
  import javax.swing.AbstractAction;
  import javax.swing.Icon;
  import javax.swing.ImageIcon;
  import javax.swing.JButton;
  import javax.swing.JComponent;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.KeyStroke;
  import javax.swing.SwingUtilities;
  import javax.swing.border.LineBorder;
  
  public class NewClass1 {
  
      public static void main(String[] args) {
          createAndShowJFrame();
      }
  
      public static void createAndShowJFrame() {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
  
                  JFrame frame = createJFrame();
                  frame.setVisible(true);
  
              }
          });
      }
  
      private static JFrame createJFrame() {
          JFrame frame = new JFrame();
          //frame.setResizable(false);//make it un-resizeable
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setTitle("Test");
  
          ArrayList&lt;BufferedImage&gt; images = null;
  
          try {
              images = getImagesArrayList();
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
          final ImageViewPanel imageViewPanel = new ImageViewPanel(images);
          JScrollPane jsp = new JScrollPane(imageViewPanel);
          jsp.setPreferredSize(new Dimension(400, 400));
          frame.add(jsp);
  
         final  javax.swing.JComboBox filter = new javax.swing.JComboBox&lt;&gt;();
          filter.addItem("All");
          filter.addItem("Profile Pic");
          filter.addItem("Company Logo");
          filter.addItem("Product Img");
  
  
          JPanel controlPanel = new JPanel();
          JButton addLabelButton = new JButton("Delete Selected Image");
          addLabelButton.addActionListener(new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  imageViewPanel.removeFocusedImageLabel();
              }
          });
          JLabel label =new JLabel("Filter By :");
          filter.addActionListener(new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent e) {
  
                  String cat=(String) filter.getSelectedItem();
  
                 createJFrame(cat);
              }
          });
          controlPanel.add(addLabelButton);
          controlPanel.add(label);
          controlPanel.add(filter);
          frame.add(controlPanel, BorderLayout.NORTH);
          frame.pack();
  
  
  
          return frame;
      }
  
      private static ArrayList&lt;BufferedImage&gt; getImagesArrayList(String cat) throws Exception {
          System.out.println(cat);
  
          ArrayList&lt;BufferedImage&gt; images = new ArrayList&lt;&gt;();
          if(cat.equals("Profile Pic"))
          images.add(resize(ImageIO.read(new URL("http://192.168.1.25:8080/pic/ProfilePic/1.jpg")), 100, 100));
          else if(cat.equals("Product Img"))
          {
          images.add(resize(ImageIO.read(new URL("http://192.168.1.25:8080/pic/ProductImg/2.jpg")), 100, 100));
  
          }
          return images;
      }
  
  private static ArrayList&lt;BufferedImage&gt; getImagesArrayList() throws Exception {
         ArrayList&lt;BufferedImage&gt; images = new ArrayList&lt;&gt;();
         images.add(resize(ImageIO.read(new URL("http://localhost:8080/pic/All/a.jpg")), 100, 100));
         images.add(resize(ImageIO.read(new URL("http://localhost:8080/pic/All/b.jpg")), 100, 100));
             return images;
     }
      public static BufferedImage resize(BufferedImage image, int width, int height) {
          BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
          Graphics2D g2d = (Graphics2D) bi.createGraphics();
          g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
          g2d.drawImage(image, 0, 0, width, height, null);
          g2d.dispose();
          return bi;
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/W8GrB.png" alt="This should be shown on selection of &quot;Profile Pic&quot; item">
  <img src="https://i.stack.imgur.com/Rk46w.png" alt="This Image should be shown on selection of &quot;Product Img&quot; item"></p>