title: JLabel wont show up on button click
body: <p>This is my first GUI so any advice is good advice here but mainly I'm just trying to work out why my <code>errorLabel</code> wont show up. I've tried <code>setVisible</code>, <code>setOpaque</code>, having the location set manually and finally (as you can see below) just making it its own panel to sit on and it still won't show up on button press.</p>
  <p>Any ideas?</p>
  <pre><code>package GUI;
  
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import javax.swing.*;
  
  
  /**
   *
   * @author User
   */
  public class AddChair extends JFrame {
  
      private final int FRAME_HEIGHT = 600;
      private final int FRAME_WIDTH = 400;
      private final String ADD_CHAIR_TITLE = &quot;Chair&quot;;
      private final int TEXT_BOX_WIDTH = FRAME_WIDTH / 4;
      private final int TEXT_BOX_HEIGHT = 25;
  
      private JPanel basePanel;
      private JPanel leftPanel;
      private JPanel rightPanel;
      private JPanel lowerPanel;
      private JPanel itemIDPanel;
      private JPanel woodTypePanel;
      private JPanel armrestPanel;
      private JPanel quantityPanel;
      private JPanel itemIDInputPanel;
      private JPanel woodTypeInputPanel;
      private JPanel quantityInputPanel;
      private JPanel armrestInputPanel;
      private JPanel confirmCancelPanel;
      private JPanel errorPanel;
  
      private JTextField itemIDTextField;
      private JTextField quantityTextField;
  
      private JRadioButton walnut;
      private JRadioButton oak;
      private JRadioButton yes;
      private JRadioButton no;
      
      private JButton confirmButton;
      private JButton cancelButton;
  
      public AddChair() {
          frameSetup();
          add(basePanel());
      }
  
      private void frameSetup() {   // sets up base frame
          setSize(FRAME_WIDTH, FRAME_HEIGHT);
          setVisible(true);
          setAlwaysOnTop(true);
          setTitle(ADD_CHAIR_TITLE);
          setLocationRelativeTo(null);
      }
  
      private JPanel basePanel() {   //sets up a base panel to arrange other panels on
          basePanel = new JPanel(new BorderLayout());
          basePanel.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT));
          basePanel.add(leftPanel(), BorderLayout.WEST);
          basePanel.add(rightPanel(), BorderLayout.EAST);
          basePanel.add(lowerPanel(), BorderLayout.SOUTH);
          return basePanel;
      }
  
      private JPanel leftPanel() {   //sets up the left panel which will contain labels
          leftPanel = new JPanel();
          leftPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4));
          leftPanel.setVisible(true);
          labelPanels();
          labels();
          return leftPanel;
      }
  
      private void labelPanels() {//sets up the panels for the labels
          itemIDPanel = new JPanel();
          woodTypePanel = new JPanel();
          armrestPanel = new JPanel();
          quantityPanel = new JPanel();
  
          itemIDPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          woodTypePanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          armrestPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          quantityPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
  
          itemIDPanel.setVisible(true);
          woodTypePanel.setVisible(true);
          armrestPanel.setVisible(true);
          quantityPanel.setVisible(true);
  
          leftPanel.add(itemIDPanel);
          leftPanel.add(woodTypePanel);
          leftPanel.add(armrestPanel);
          leftPanel.add(quantityPanel);
      }
  
      private void labels() {   //sets up the and adds the labels for the user 
          JLabel itemIDLabel = new JLabel(&quot;Item ID:&quot;);
          JLabel woodTypeLabel = new JLabel(&quot;Wood Type:&quot;);
          JLabel armrestLabel = new JLabel(&quot;Armrest:&quot;);
          JLabel quantityLabel = new JLabel(&quot;Quantity:&quot;);
  
          itemIDLabel.setVisible(true);
          woodTypeLabel.setVisible(true);
          armrestLabel.setVisible(true);
          quantityLabel.setVisible(true);
  
          itemIDPanel.add(itemIDLabel);
          woodTypePanel.add(woodTypeLabel);
          armrestPanel.add(armrestLabel);
          quantityPanel.add(quantityLabel);
      }
  
      private JPanel rightPanel() {   // sets up the right panel which will contain the user input objects
          rightPanel = new JPanel();
          rightPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4));
          rightPanel.setVisible(true);
          userInputPanels();
          return rightPanel;
      }
  
      private void userInputPanels() {//sets up the panels for the labels
          itemIDInputPanel = new JPanel();
          woodTypeInputPanel = new JPanel();
          armrestInputPanel = new JPanel();
          quantityInputPanel = new JPanel();
  
          itemIDInputPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          woodTypeInputPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          armrestInputPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
          quantityInputPanel.setPreferredSize(new Dimension(FRAME_WIDTH / 2, FRAME_HEIGHT * 3 / 4 / 5));
  
          itemIDInputPanel.setVisible(true);
          woodTypeInputPanel.setVisible(true);
          armrestInputPanel.setVisible(true);
          quantityInputPanel.setVisible(true);
  
          userInputs();
  
          rightPanel.add(itemIDInputPanel);
          rightPanel.add(woodTypeInputPanel);
          rightPanel.add(armrestInputPanel);
          rightPanel.add(quantityInputPanel);
      }
  
      private void userInputs() {   // sets up and adds to the right panel the user input objects
          itemIDTextField = new JTextField(&quot;&quot;);
          walnut = new JRadioButton(&quot;Walnut&quot;);
          oak = new JRadioButton(&quot;Oak&quot;);
          yes = new JRadioButton(&quot;Yes&quot;);
          no = new JRadioButton(&quot;No&quot;);
          quantityTextField = new JTextField(&quot;&quot;);
          
          itemIDTextField.setPreferredSize(new Dimension(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT));
          itemIDInputPanel.add(itemIDTextField);
  
          ButtonGroup woodTypeGroup = new ButtonGroup();
          woodTypeGroup.add(oak);
          woodTypeGroup.add(walnut);
          woodTypeInputPanel.add(walnut);
          woodTypeInputPanel.add(oak);
  
          ButtonGroup armrestGroup = new ButtonGroup();
          armrestGroup.add(yes);
          armrestGroup.add(no);
          armrestInputPanel.add(yes);
          armrestInputPanel.add(no);
  
          quantityTextField.setPreferredSize(new Dimension(TEXT_BOX_WIDTH, TEXT_BOX_HEIGHT));
          quantityInputPanel.add(quantityTextField);
      }
  
      private JPanel lowerPanel() {   // sets up the lower panel for confirm and cancel buttons
          lowerPanel = new JPanel(new BorderLayout());
          lowerPanel.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT / 4));
          lowerPanel.setVisible(true);
          confirmCancelPanel();
          errorPanel();
          confirmCancelButtons();
          return lowerPanel;
      }
      
      private void confirmCancelPanel(){
          confirmCancelPanel = new JPanel();
          confirmCancelPanel.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT / 8));
          confirmCancelPanel.setBackground(Color.blue);
          confirmCancelPanel.setVisible(true);
          lowerPanel.add(confirmCancelPanel, BorderLayout.NORTH);
      }
      
      private void errorPanel(){
          errorPanel = new JPanel();
          errorPanel.setPreferredSize(new Dimension(FRAME_WIDTH, FRAME_HEIGHT / 8));
          errorPanel.setBackground(Color.yellow);
          errorPanel.setVisible(true);
          lowerPanel.add(errorPanel, BorderLayout.SOUTH);
      }
      
      private void confirmCancelButtons(){
          confirmButton = new JButton(&quot;Confirm&quot;);
          cancelButton = new JButton(&quot;Cancel&quot;);
          
          confirmButton.setVisible(true);
          cancelButton.setVisible(true);
          
          confirmCancelPanel.add(confirmButton);
          confirmCancelPanel.add(cancelButton);
          
          cancelButtonLogic();
          confirmButtonLogic();
      }
      
      private void cancelButtonLogic(){
          cancelButton.addActionListener((ActionEvent ae) -&gt; {
              this.dispose();
          });
      }
      
      private void confirmButtonLogic(){
          confirmButton.addActionListener((ActionEvent ae) -&gt; {
              errorMessage();
              
          });
      }
      
      private void errorMessage(){
          JLabel errorLabel = new JLabel(&quot;Error&quot;);
          errorLabel.setOpaque(true);
          errorLabel.setVisible(true);
          errorLabel.setForeground(Color.BLACK);
          errorPanel.add(errorLabel);
      }
  }
  </code></pre>