我试图使用table.setBound,但我认为它不起作用。
这是代码。
public GUI() {
this.setSize(800, 400);
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle("GUI");
JPanel panel = new JPanel();
this.add(panel);
String[] col = { "Name", "grade" };
Object[][] cells = {{ "A", "B" }, { "C", "D" }, { "E", "F" }};
JTable table = new JTable(cells, col);
table.setBounds(0, 0, 600, 100);
panel.add(new JScrollPane(table));
this.setVisible(true);
}
这是输出