我的 JTable 没有扩展到它所在面板的全宽

My JTable does not expand to full width of panel it is in

如何让我的 JTable 使用父面板的全部可用资源?我尝试使用 setSize 或 setPreferredSize,但没有用。后者实际上产生了 table.

的一个非常小的版本
JPanel panel = new JPanel(new GridBagLayout());
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.insets = new Insets(0, 0, 25, 15); 
String[] columnNames = {"A", "B", "C", "D", "E"};
        Object[][] data = new Object[20][columnNames.length];
        for( int i = 0; i < 20; i++ ){
            data[i] = new Object[]{"Some other stuff that is long", "K", "1234567891011121314", "R", "T"};
        }

        JTable skillTable = new JTable(data, columnNames);
        skillTable.setFillsViewportHeight(true );
        JScrollPane scrollTable = new JScrollPane(skillTable);
        constraints.fill = constraints.HORIZONTAL;
        panel.add(scrollTable, constraints);

这是它的样子:http://i.stack.imgur.com/P4b6A.png

选择 BorderLayout 简洁

 JPanel panel = new JPanel(new BorderLayout());
    String[] columnNames = {"A", "B", "C", "D", "E"};
    Object[][] data = new Object[20][columnNames.length];
    for (int i = 0; i < 20; i++) {
        data[i] = new Object[]{"Some other stuff that is long", "K", "1234567891011121314", "R", "T"};
    }

    JTable skillTable = new JTable(data, columnNames);
    skillTable.setFillsViewportHeight(true);
    JScrollPane scrollTable = new JScrollPane(skillTable);
    panel.add(scrollTable, BorderLayout.CENTER);

    //as you said you want to add a button as well
    JPanel buttonpanel=new JPanel();
    buttonpanel.add(new JButton("Test"));
    panel.add(buttonpanel,BorderLayout.SOUTH);