How to add dynamically rows number in jTable - Java
Most of the programming now a days required dynamically create controller such as button, textbox and also table. Today i want to show how to dynamically set rows number in jTable Swing Controls. Firstly is to set the DefaultTableModel and assign to jTable. Here is the example : The DefaultTableModel import javax.swing.table.DefaultTableModel; : : String colNames[] = {"Name", "Edit", "View"}; DefaultTableModel dtm = new DefaultTableModel(null,colNames); Do looping to add rows in jTable for(int i=0; i < listOfString .size();i++){ dtm.addRow(new String[3]); } Assign to jTable jTable2.setModel(dtm); The full Code : String colNames[] = {"Name", "Edit", "View"}; DefaultTableModel dtm = new DefaultTableModel(null,colNames); List<String> listOfString = new ArrayList<>(); listOfString.add("1"); ...