1, erstellen Sie eine Datenstruktur
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, DefaultTableModel erstellen
DefaultTableModel model = new DefaultTableModel(data, columnNames);
3, erstellen Sie JTable
JTable table = new JTable(model);
4, in JScrollPane setzen
JScrollPane spane = new JScrollPane(table);
5, in JFrame setzen
JFrame frame = new JFrame("Title");
frame.setSize(500, 500);
frame.add(spane);
6, zeichnen
frame.setVisible(true);
Recommended Posts