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"); listOfString.add("2"); listOfString.add("3"); listOfString.add("4"); listOfString.add("5"); listOfString.add("6"); listOfString.add("7"); for(int i=0; i < listOfString .size();i++){ dtm.addRow(new String[3]); } jTable2.setModel(dtm);
By Mohd Zulkamal
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
0 comments:
Post a Comment