title: How to put an image on a JButton?
body: <p>I am writing a program that requires I have a button with an image over top of it, however, so far, I have not been able to get it to work.  I have checked several other posts on this site, including <a href="https://stackoverflow.com/questions/4801386/how-do-i-add-an-image-to-a-jbutton">How do I add an image to a JButton</a>.<br>
  My Code:</p>
  
  <pre><code>public class Tester extends JFrame
  {
      public Tester()
      {
          JPanel panel = new JPanel();
          getContentPane().add(panel);
          panel.setLayout(null);
  
          setTitle("Image Test");
          setSize(300,300);
          setLocationRelativeTo(null);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
  
          JButton button = new JButton();
          try 
          {
              Image img = ImageIO.read(getClass().getResource("Images\\BBishopB.gif"));
              button.setIcon(new ImageIcon(img));
          } 
          catch (IOException ex) {}
  
          button.setBounds(100,100,100,100);
          panel.add(button);
      }
  
      public static void main(String[] args)
      {
          Tester test = new Tester();
          test.setVisible(true);
      }
  }
  </code></pre>
  
  <p>When this code runs, an error results: Exception in thread "main" java.lang.IllegalArgumentException: input == null!  This error occurs at the line:</p>
  
  <pre><code>Image img = ImageIO.read(getClass().getResource("Images\\BBishopB.gif"));
  </code></pre>
  
  <p>I don't think that this error is due to the file not being found by java code, as my Images folder is in the src folder (I am using Eclipse) as recommended by the above link. 
  <br>
  Does anyone have any ideas to what the problem may be? <br>
  Thanks.</p>