title: Adding image to JButton
body: <p>I want to add an image to a <code>JButton</code>. Background of the button is set to black. I tried to add the image on top of it, but nothing was shown.  Background color was black but the image was missing.</p>
  <h2>Code</h2>
  <pre><code>public class Test extends JFrame {
  
      JButton b;
      JPanel p;
  
      Test() {
          p = new JPanel(new BorderLayout());
          b = new JButton();
          b.setBackground(Color.black);
          ImageIcon img = new ImageIcon(&quot;C:\\Users\\Aksi\\Documents\\NetBeansProjects\\test'\\src\\test\\Black_B.ico&quot;);
          b.setIcon(img);
         
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setSize(400, 400);
          p.add(b);
          add(p);
         validate();
  
     }
      public static void main(String args[]) throws IOException {
          Test ob = new Test();
          ob.setVisible(true);
      }
  }
  </code></pre>