title: How to add to JTable?
body: <p>I'm trying to make a Punnett Square in Java and for that I need to edit cells in a JTable using variables.</p>
  
  <pre><code>import java.awt.BorderLayout;
  
  import javax.swing.JFrame;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  
  public class JTableCreatingDemo {
    public static void main(String args[]) {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" },
          { "Row2-Column1", "Row2-Column2", "Row2-Column3" } };
      Object columnNames[] = { "Column One", "Column Two", "Column Three" };
      JTable table = new JTable(rowData, columnNames);
  
      JScrollPane scrollPane = new JScrollPane(table);
      frame.add(scrollPane, BorderLayout.CENTER);
      frame.setSize(300, 150);
      frame.setVisible(true);
  
    }
  }
  </code></pre>
  
  <p>I'm learning about JTable from that code and is there any way I can add to rowData[][] and columnNames[]? </p>
  
  <p>Or any other way to make a Punnett Square program using JTable?</p>
  
  <p>Edit:</p>
  
  <p>This is the method that includes the table</p>
  
  <pre><code>public void f12(List&lt;String&gt; fin, int a){
      JFrame gamFrame = new JFrame();
  
      Object column[] = {"Gametes", "Gametes"};
      Object rowGam[][] = {};
  
      final DefaultTableModel model = new DefaultTableModel(rowGam, column);
  
      JTable gametes = new JTable(model);
  
      double d = Math.pow(10,a - 1);
      String[] rowData = new String[2];
      for (int e = a - 1; e &gt; 0; e--){
          d += Math.pow(10, e - 1);
      }
      String a1 = "", a2 = "";
  
      if (d &gt; 10){
          a1 = fin.get(0);
      }
      if (d == 11){
          a2 = fin.get(1);
      }
      rowData[1] = String.format(a1 + a2);
      model.addRow(rowData);
  
  
  
      JScrollPane scrollPane = new JScrollPane(gametes);
  
      gamFrame.add(scrollPane, BorderLayout.CENTER);
      gamFrame.pack();
      gamFrame.setVisible(true);
  }
  </code></pre>
  
  <p>The </p>
  
  <pre><code>if (d &gt; 10){
      a1 = fin.get(0);
  }
  if (d == 11){
      a2 = fin.get(1);
  }
  </code></pre>
  
  <p>will be a little more complicated later but the table doesn't work with this either.</p>
  
  <p>In the above case, fin = {A, B} and a = 2.</p>
  
  <p>And my expected result is a table with one column (Gametes) and one row below it (AB).</p>