1, create a data structure
String[] columnNames = { "1", "2", "3", "4" };
String[] data1 = { "A", "B", "C", "D" };
String[] data2 = { "E", "F", "G", "H" };
String[] data3 = { "I", "J", "K", "L" };
String[] data4 = { "M", "N", "O", "P" };
String[] data5 = { "Q", "R", "S", "T" };
String[][] data = { data1, data2, data3, data4, data5 };
2, Create DefaultTableModel
DefaultTableModel model = new DefaultTableModel(data, columnNames);
3, Create JTable
JTable table = new JTable(model);
4, put in JScrollPane
JScrollPane spane = new JScrollPane(table);
5, put in JFrame
JFrame frame = new JFrame("Title");
frame.setSize(500, 500);
frame.add(spane);
6, draw
frame.setVisible(true);
Recommended Posts