title: Java Swing show icon button and JLabel
body: <p>I am trying to make a simple program to learn about Java Swing. I want an Icon button and a label to show the latest ActionEvent. However, with this code:</p>
  <pre class="lang-java prettyprint-override"><code>import javax.swing.*;
  import java.awt.event.*;
  import java.net.*;
  public class MyProgram implements ActionListener {
      JButton b1;
      JFrame f;
      JLabel ael;
      int i = 1;
      MyProgram() throws Exception {
          f = new JFrame();
          URL img = new URL(&quot;https://c.tenor.com/cSNnlTEM4rUAAAAM/booze-man.gif&quot;);
          ImageIcon imgIcon = new ImageIcon(img);
          b1 = new JButton(&quot;Click me or you'll be punched!&quot;, imgIcon);
          b1.setHorizontalTextPosition(JButton.CENTER);
          b1.setVerticalTextPosition(JButton.TOP);
          b1.addActionListener(this);
          b1.setActionCommand(&quot;Button click&quot;);
          f.getContentPane().add(b1);
          ael = new JLabel(&quot;Latest action event: NULL&quot;);
          f.add(ael);
          f.pack();
          f.setLayout(null);
          f.setVisible(true);
      }
      public static void main(String[] args) throws Exception {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                  try {
                      new MyProgram();
                  }catch(Exception ex){}
              }
          });
      }
      public void actionPerformed(ActionEvent ae) {
          System.out.println(ae.getActionCommand());
          b1.setText(&quot;Thanks!&quot;);
          ael.setText(&quot;Latest action event: &quot; + ae.getActionCommand());
          try {
          b1.setIcon(new ImageIcon(new URL(&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Emoji_u1f44d.svg/120px-Emoji_u1f44d.svg.png&quot;)));
          }catch(Exception ex){}
          b1.setActionCommand(&quot;Button click after activation number: &quot; + i);
          i++;
      }
  }
  </code></pre>
  <p>It only shows the <code>ael</code> label.
  I have tried packing the frame twice, but then it will only show the <code>b1</code> button.
  Why is this and how can I fix it?</p>