Hi,
I wrote the followiing code for a Jtable:

public class simpletabletest extends JPanel{

     public simpletabletest() { 



      String[][] data = {  {"...", "...", "...", "..."}, 
                           {"...", "...", "...", "..."}, 
                           {"...", "...", "...", "..."}}; 

      String[] Columns = {"Name", "LastName", "Phone", "MobilePhone"}; 

      //DefaultTableModel model = new DefaultTableModel(data, Columns); 
      JTable table = new JTable(data, headers); 
      table.setPreferredScrollableViewportSize(new Dimension(500,60));
      table.setFillsViewportHeight(true);


      JScrollPane jps = new JScrollPane(table);
      add(jps);

   } 
   }

If i have a main method and like bellow the table t appears to the JFrame

public static void main(String[] args) {

        JFrame jf = new JFrame();
        simpletabletest t = new simpletabletest();
        jf.setSize(600, 500);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.add(t);

    }

I use NetBeans and i make a newJframe form from design. After that in formWindowOpened event i write

simpletabletest t = new simpletabletest();
add(t);

but the table doesn't appears to the JFrame.
Can someone help me with this?

thanks in advance.

Comments
there should be Column instead of headers

Sorry my English is not very good, but I use NetBeans to build the table use this code:

 private void atualizaPesquisa() {

        DefaultTableModel modeloProdutosCusto = new javax.swing.table.DefaultTableModel(
                new Object[][]{},
                new String[]{"ID", "Descrição", "Cód. Planilha", "Cód.", "Descrição Complementar"}) {

            Class[] types = new Class[]{
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class};
            boolean[] canEdit = new boolean[]{
                false, false, false, false, false};

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };
          String[] linha = new String[5];  
                for (int j = 0; j <= 4; j++) {
                    if (j == 0) {
                        linha[j] = "1";
                    }
                    if (j == 1) {
                        linha[j] = "AA";
                    }
                    if (j == 2) {
                        linha[j] = "1";
                    }
                    if (j == 3) {
                        linha[j] = "1";
                    }
                    if (j == 4) {
                        linha[j] = "dddd";
                    }

                }
                modeloProdutosCusto.addRow(linha);

   }
This article has been dead for over six months. Start a new discussion instead.