JTable 在 JScrollPane 中不可见

问题描述

我在 JScrollPane 中有一个 JTable。我只想在按下特定按钮时显示表格,否则不应显示。

为了体现这一点,我在声明时将 ScrollPane 的 setVisible 方法设置为 false,并在 JButton 的 true 方法中将其设置为 actionPerformed

但是即使我按下 JButton 也看不到 JTable。

这是我的代码:

     public class TableSample{
        private JTable table;
     ....
        private void initialize() {
            JScrollPane scrollPane = new JScrollPane();
            table = new JTable(new DefaultTableModel(new Object[][] {{null,null},{null,},new String[] {"column1","column2"}));
            scrollPane.setViewportView(table);
            scrollPane.setVisible(false);
            JButton button = new JButton("Show Table");
            button.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {        
                     ....
                     scrollPane.setVisible(true);
                     ....
                }
            });
     ....
        }

我使用了组布局,因此将 ScrollPane 添加到具有组布局的框架中。

当我根本不更改 setVisible 时,JTable 也是可见的(默认情况下为 true

感谢任何帮助...

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)