title: Draw image in Java GUI
body: <p>I am trying to display an image in a <code>JFrame</code> GUI in Java. I have successfully loaded the image from a resource file and been able to display the image in a <code>JOptionPane</code>. This was achieved using a <code>JLabel</code> containing a Image Icon in the constructor. When trying to add this image to a <code>JPanel</code> nothing is displayed.</p>
  
  <pre><code>JLabel imgLabel1 = new JLabel(new ImageIcon(tsr.getTileImage(1,1)),JLabel.CENTER);
  jpnDisplay.add(imgLabel1);
  </code></pre>
  
  <p>tsr is my custom code for getting a subimage from a tileset. The image returned is of type <code>BufferedImage</code>.</p>
  
  <p>One thing I did notice is if I display the image in a <code>JOptionPane</code> then add it to the <code>JPanel</code> the image is displayed. I am unsure why this is.</p>
  
  <pre><code>JLabel imgLabel1 = new JLabel(new ImageIcon(tsr.getTileImage(1,1)),JLabel.CENTER);
  JOptionPane.showMessageDialog(null, imgLabel1,"Label",-1);
  jpnDisplay.add(imgLabel1);`enter code here
  </code></pre>
  
  <p>--EDIT--</p>
  
  <p>After playing around with my code, I have discovered my issue was not with the way I was trying to display the images, but that for some reason my <code>JFrame</code> was not repainting unless a <code>JOptionPane</code> was shown before the <code>JFrame</code> was shown. It also only paints the same instance that was shown in the <code>JOptionPane</code>. Any other images to be painted get ignored. The reason is unclear.</p>