Jtable行和列不在最小化窗口中显示

时间:2019-03-03 15:01:45

标签: java netbeans jtable

在JTable中插入数据并运行项目后,框架不会在最小化的窗口中显示行和列,而是在窗口最大化时显示。我不知道问题是什么。

    JFrame f = new JFrame(); // Java Frame 
    f.setLayout(new BorderLayout());
    f.setTitle("JTable Example");   
    f.setSize(500, 200);

    DefaultTableModel model = new DefaultTableModel();
    JTable  table = new JTable(){

     private static final long serialVersionUID = 1L;

        @Override
        public Class getColumnClass(int column) {
            switch (column) {
                case 0:
                    return String.class;

                case 1:
                     return String.class;

                default:
                   return Boolean.class;
            }
        }
    };



    Object[] columnNames = {"Username","Email","Select"}; 
    model.setColumnIdentifiers(columnNames);
    table.setModel(model);
    table.setBounds(30, 40, 200, 300);




   JButton mail = new JButton("mail");
   JPanel btnPnl = new JPanel(new BorderLayout()); 
   JPanel topBtnPnl = new JPanel(new FlowLayout(FlowLayout.TRAILING));
   topBtnPnl.add(mail);
    // mail.addActionListener(this);
    btnPnl.add(topBtnPnl, BorderLayout.CENTER);
    f.add(table.getTableHeader(), BorderLayout.NORTH);
    f.add(table, BorderLayout.CENTER);
    f.add(btnPnl, BorderLayout.SOUTH);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
    JScrollPane sp = new JScrollPane(table);
    f.add(sp); 

0 个答案:

没有答案