title: How do I get JFrame to display my panel?
body: <p>I am learning to use JFrame so that I can start building some applications however, I am having a great deal of trouble getting my panel to display components. The code that I have created so far is just to practice and get a feel for the actual JFrame library.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    import java.awt.Dimension;
      import java.awt.Toolkit;
      import javax.swing.*;
  
      public class GUI extends JFrame {
  
      public static void main(String[] args){
          new GUI();          
      }
  
      /*
       * This is the constructor of the GUI. It sets the dimension,
       * the visibility, and the positioning of the frame relative
       * to the users dimension of their screen size. 
       */
      public GUI(){
          //'this' is in reference to the frame being created
          this.setSize(500, 400);
          //this.setLocationRelativeTo(null);
          this.setVisible(true);
  
          Toolkit tk = Toolkit.getDefaultToolkit();
          Dimension dim = tk.getScreenSize();     //will hold height and width
  
          //Grabs the height and width positioning
          //of the screen and centers the window
          int xPos = (dim.width /2) - (this.getWidth() / 2);
          int yPos = (dim.height /2) - (this.getHeight() / 2);
  
          this.setLocation(xPos, yPos);
  
          //This prevents someone from resizing the frame
          //By default this method is true.
          this.setResizable(false);
  
          //Sets how the frame will close
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          //Sets the title of the frame
          this.setTitle("Woot I created a frame!");
  
          /*
           * The panel is used to hold all of the different
           * labels and components within the frame.
           */
          JPanel thePanel = new JPanel();
  
          JLabel label1 =  new JLabel("Tell me something");
          label1.setToolTipText("Click if you need help");
  
          thePanel.add(label1);
  
          //Creates a button
          JButton button1 = new JButton("OK");
          button1.setBorderPainted(true);
          button1.setContentAreaFilled(true);
          button1.setToolTipText("This is my button");
          thePanel.add(button1);
  
          //Creates a text field
          JTextField txtField = new JTextField("Type here", 15);
  
          txtField.setToolTipText("It's a field");
          //Adds txtField to the Frame
          thePanel.add(txtField);
  
          //Adds thePanel to the Frame originally created
          this.add(thePanel);
      }    
  } 
  </code></pre>
  
  <p>When I run this, a display window appears but I do not see the text field. When I comment out the text field, then the button and the label appear as they should. </p>