1, créer une structure de données
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, créer DefaultTableModel
DefaultTableModel model = new DefaultTableModel(data, columnNames);
3, créez JTable
JTable table = new JTable(model);
4, mis dans JScrollPane
JScrollPane spane = new JScrollPane(table);
5, mettre dans JFrame
JFrame frame = new JFrame("Title");
frame.setSize(500, 500);
frame.add(spane);
6, dessiner
frame.setVisible(true);
Recommended Posts