title: Java JTable Column headers not showing
body: <p>My code (Logic-wise) is all good, the only problem is that the column headers do not show up in the 2 tables (table and tableS, one for teacher and one for student details). How do I make them show?</p>
  <pre><code>        import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.io.*;
  import java.util.*;
  
  
  public class Display
  {
      ArrayList&lt;Student&gt; stud1 = new ArrayList&lt;Student&gt;();
      ArrayList&lt;SubjectTeacher&gt; sTeach1 = new ArrayList&lt;SubjectTeacher&gt;();
  
      //For Display Teachers
      private  JTable table;
      private  JFrame f;
      private int i;
  
      //For DisplayStudents
      private JTable tableS;
      private JFrame fS;
      private int iS;
  
  
      //Displays Teachers
      public void displayTeachers()
      {
  
              f = new JFrame(&quot;Teachers&quot;);
  
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.setSize(500,400);
              f.setVisible(true);
  
  
  
          String[] columnNames =  {&quot;Name&quot;, &quot;Surname&quot;, &quot;ID&quot;, &quot;Pay&quot;, &quot;Subject&quot;};
  
          sTeach1 = Stores.getTeach();
          i = sTeach1.size();
  
  
          Object[][] data = new Object[i+1][5];
  
  
  
              for (int j = 0; j&lt;sTeach1.size(); j++)
              {
                  {
                      SubjectTeacher myTeach = sTeach1.get(j);
                       data[j][0] = myTeach.getName();
                       data[j][1] = myTeach.getSurname();
                       data[j][2] = myTeach.getID();
                       data[j][3] = myTeach.getPay();
                       data[j][4] = myTeach.getSubjectID();
                  };
              }
  
  
  
  
      JTable table = new JTable (data, columnNames);
      f.add(table);
  
      }
  
  
  
      //Displays Students
      public void displayStudents()
      {
  
          System.out.println(stud1.size());
  
              fS = new JFrame(&quot;Students&quot;);
  
              fS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              fS.setSize(700,600);
              fS.setVisible(true);
  
  
  
          String[] colNames =  {&quot;Name&quot;, &quot;Surname&quot;, &quot;ID&quot;, &quot;Computer&quot;, &quot;Physics&quot;, &quot;Maths&quot;, &quot;Tests&quot;, &quot;Passes&quot;, &quot;Fails&quot;};
  
  
          stud1 = Stores.getStud();
          iS = stud1.size();
  
          Object[][] info = new Object[iS+1][9];
  
  
  
  
          for (int j = 0; j&lt;stud1.size(); j++)
              {
                  {
  
  
                      Student myStud = stud1.get(j);
  
                   info[j][0] = myStud.getName();
                   info[j][1] = myStud.getSurname();
                   info[j][2] = myStud.getID();
                   info[j][3] = myStud.getSubject(1);
                   info[j][4] = myStud.getSubject(2);
                   info[j][5] = myStud.getSubject(3);
                   info[j][6] = myStud.getTestsTaken();
                   info[j][7] = myStud.getPasses();
                   info[j][8] = myStud.getFails();
                  };
              }
  
  
  
  
      JTable tableS = new JTable (info, colNames);
      fS.add(tableS);
  
      }
  
  }
  </code></pre>