2011-08-11 13 views
6

¿Cómo puedo agregar datos a JTable mientras trabajo con netbeans. Netbeans en él está detrás código hace así:agregar datos a JTable cuando se trabaja con netbeans

jTable1 = new javax.swing.JTable(); 
jTable1.setModel(new javax.swing.table.DefaultTableModel(
     new Object [][] { 
      {null, null}, 
      {null, null}, 
      {null, null}, 
      {null, null} 
     }, 
     new String [] { 
      "Name", "Branch" 
     } 
    ) { 
     boolean[] canEdit = new boolean [] { 
      false, false 
     }; 

     public boolean isCellEditable(int rowIndex, int columnIndex) { 
      return canEdit [columnIndex]; 
     } 
    }); // THIS IS THE SNIPPET GENERATED BY NETBEANS 
    //(I have already created a table using the drag and drop fetaure of netbeans and this is the back snippet generated) 

El objeto de matriz 2-D y de tipo Alfa tienen acceso local, por lo que no se puede utilizar para llenarlo cuando quiero en la mitad del programa. (en alguna función)

enter image description here

al igual que en la tabla anterior voy a añadir el nombre y la rama mientras que en algunos function.But cómo puedo hacer esto?

¿Alguien puede indicar una manera para que pueda agregar datos a JTable?

Respuesta

16
jTable1.getModel().setValueAt(value, row, column); 
+0

¡perfecto! Eso es lo que estaba buscando – saplingPro

+0

awesome .. thanks .. :) – Amarnath

1

jTable1.getModel().setValueAt(value, row, column);

+1

Por favor, ponga cualquier comentario a su respuesta. Las respuestas de solo código no son valiosas y no son bienvenidas aquí. Gracias. – trejder

-1
try { 
    pst = con.prepareStatement("select * from emp"); 
    ResultSet rs = pst.executeQuery(); 
    int i = 0; 
    if (rs.next()) { 
    String uname = rs.getString("contact_id"); 
    String email = rs.getString("first_name"); 
    String pass = rs.getString("last_name"); 
    String cou = rs.getString("phone"); 
    model.addRow(new Object[]{uname, email, pass, cou}); 
    i++; 
} 
Cuestiones relacionadas