title: How do I fill data in a JTable?
body: <p>I am trying to update my table, but it is not working. The table does not show up until the entire program calling it is done. How can I change this? Upon opening the window, I would like to fill the <code>JTable</code> with data. If I stop the execution of the code, the table is filled with data. Do I need a thread? How would I use one correctly? My code is below.</p>
  
  <pre><code>public class TestGUI extends DefaultTableCellRenderer implements TeststepEventListener {
  
      public JFrame frame;
      private JTable testcase_table;
      private JTable teststep_table;
  
      /**
       * Create the application.
       */
      public TestGUI() {
          initialize();
          frame.setVisible(true);
      }
  
      /**
       * Initialize the contents of the frame.
       */
      private void initialize() {
          frame = new JFrame();
          frame.setBounds(100, 100, 800, 600);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().setLayout(null);
  
          JProgressBar progressBar = new JProgressBar();
          progressBar.setBounds(50, 68, 700, 14);
          frame.getContentPane().add(progressBar);
  
          JTextPane txtpnAutomotiveHmi = new JTextPane();
          txtpnAutomotiveHmi.setText("Automotive HMI");
          txtpnAutomotiveHmi.setBounds(362, 21, 205, 20);
          frame.getContentPane().add(txtpnAutomotiveHmi);
  
          testcase_table = new JTable();
          testcase_table.setBounds(50, 125, 350, 426);
          frame.getContentPane().add(testcase_table);
  
          teststep_table = new JTable();
          teststep_table.setBounds(399, 125, 350, 426);
          frame.getContentPane().add(teststep_table);
      }
      private boolean testcase = true;
  
      @Override
      public void myEventOccurred(TeststepEvent event) {
          TeststepData data = event.data();
          if (testcase) {
              set_values(data.getDoc(), data.getTestcase());
          }
          testcase = false;
  
      }
      private int i = 0;
      LinkedList names = new LinkedList();
  
      private void set_values(Document doc, int testcase) {
          frame.setTitle("Wuratbrot" + i);
          i++;
          Element element = doc.getRootElement();
          names.clear();
          if (element != null) {
              List&lt;Element&gt; testCases = element.getChildren();
              //testcase_table.removeAll();
              //String[] title = {"Testcases"};
  
  
              for (Element testCase : testCases) {
                  names.add(testCase.getAttributeValue("name"));
              }
  
              DisplayData(names);
          }
  
          testcase_table.revalidate();
          frame.validate();
      }
  
      private void DisplayData(List&lt;String&gt; Testcases) {
  
          DefaultTableModel aModel = new DefaultTableModel() {
              //setting the jtable read only
              @Override
              public boolean isCellEditable(int row, int column) {
                  return false;
              }
          };
          //setting the column name
          Object[] tableColumnNames = new Object[1];
          tableColumnNames[0] = "TestCases";
  
  
          aModel.setColumnIdentifiers(tableColumnNames);
          if (Testcases == null) {
  
              testcase_table.setModel(aModel);
  
              return;
          }
  
          Object[] objects = new Object[1];
          ListIterator&lt;String&gt; lstrg = Testcases.listIterator();
          //populating the tablemodel
          while (lstrg.hasNext()) {
              String newcus = lstrg.next();
              objects[0] = newcus;
  
  
              aModel.addRow(objects);
          }
  
          //binding the jtable to the model
          testcase_table.setModel(aModel);
      }
  }
  </code></pre>