Adding data to JTable when working with netbeans

How to add data to JTable while working with netbeans. Netbeans in this reverse code is as follows:

 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) 

The 2-D object array and String array have local access, so I cannot use it when I want in the middle of the program. (in some function)

enter image description here

as in the above table, I will add a name and branch in some functions. But how can I do this?

Can someone tell me so that I can add data to JTable?

+6
source share
4 answers
 jTable1.getModel().setValueAt(value, row, column); 
+17
source

your question is not clear to me, but there is a basic JTable tutorial , lots of examples here or here , there is an example hoe to add value to TableCell at runtime

+1
source

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

+1
source
 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++; } 
-1
source

Source: https://habr.com/ru/post/894850/