title: Getting components of a jpanel while on runtime
body: <p>How to get components of a jpanel while on runtime in Java. I've been trying to get the components in order to perform a method with them as parameters but I realized that for some reason I can't seem to get the components while on runtime. If you need more specifics let me know, I just didn't want to make it redundant to put code because I think I can just get the answer without showing it. However let me know if it's needed. </p>
  
  <p></p>
  
  <pre><code>public SetupFrame2(int flats, int floors ) {
      initComponents();
      //Construction of the JTABLE
      jPanel1.setLayout(new BorderLayout());
      int rows = flats*floors;
      JTable tbl = new JTable();
      DefaultTableModel dtm = new DefaultTableModel();
  
      String colomnName[] = {"Floor","Flat","Area","View","Vacant"};
      dtm.setColumnIdentifiers(colomnName);
  
      for (int count = 1; count &lt;= rows; count++) {
      dtm.addRow(new Object[] {"", "", "","",""});
      }
      tbl.setModel(dtm);
      tbl.setPreferredScrollableViewportSize(new Dimension(100,250));
      tbl.setFillsViewportHeight(true);
      tbl.getTableHeader().setReorderingAllowed(false);
  
      jPanel1.add(new JScrollPane(tbl));     
  }
  </code></pre>
  
  <p>*</p>
  
  <pre><code>private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) {    
   for( Component f : jPanel1.getComponents() ) {          //It isnt getting the component on run time,
              if(f instanceof JTable){    
                  if(isJTableEmpty((JTable)f) == false){  //isJtable is a function form setupFrame2's superclass and its job so far is to return false, however its not working...
                  JOptionPane.showMessageDialog(null, "Empty", "Error", JOptionPane.ERROR_MESSAGE);
                  break;
                  }
  }
  }
  }
  </code></pre>