Java examples for Swing:JTable Model
Create JTable from DefaultTableModel
import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class Main { public void main(String[] argv) { //from w ww .ja v a 2 s .co m // Add data DefaultTableModel model = new DefaultTableModel(); model.addColumn("A"); model.addColumn("B"); model.addColumn("C"); model.addRow(new Object[] { "A1", "B1", "C1" }); model.addRow(new Object[] { "A2", "B2", "C2" }); model.addRow(new Object[] { "A3", "B3", "C3" }); JTable table = new JTable(model); } }