Swing的GridBagLayout怎么平均分配空间

Swing的GridBagLayout怎么平均分配空间?我用了weightx属性, 但是没用.

    void test3() {
        JFrame f = new JFrame("Test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(480, 800);
        Container pane = f.getContentPane();
        pane.setLayout(new GridBagLayout());

        String[] a = {
                "Lorem ipsum dolor sit amet",
                "consectetur adipisicing",
                "elit, ",
                "sed do",
                "eiusmod",
        };
        for (int i = 0; i < 5; i++) {
            GridBagConstraints c = new GridBagConstraints();
            c.gridx = i % 3;
            c.gridy = i / 3;
            c.weightx = 0.5;
            c.fill = GridBagConstraints.HORIZONTAL;
            f.add(new JButton(a[i]), c);
        }
        f.setVisible(true);
    }
查看回复