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.

rahul pareek commented: there should be Column instead of headers +0

might be caused by the used layout.

commented: Good thinking ;) +8

Yes I agree with stultuske, try make your Netbeans frame resizable, and see maybe if the JTable is added , just not in the place you though..... To add a panel to a Netbeans created frame i think you'd have to add your own code in the netbeans gui creation like this: http://stackoverflow.com/questions/816286/how-to-include-custom-panel-with-netbeans-gui-builder the link has quiete a few links that will get you started.

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);

   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.