首页 > 解决方案 > 为什么我的 jTable 的 setBounds 不起作用

问题描述

我正在尝试使用 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);
}

这是输出

在此处输入图像描述

标签: javaswingjtable

解决方案


推荐阅读