I have the following code below:

    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 1;
    c.gridy = 0;
    config.add(first = new JTextArea(), c);

    c.gridx = 1;
    c.gridy = 2;
    config.add(second = new JTextArea(), c);

    c.gridx = 1;
    c.gridy = 10;
    c.anchor = GridBagConstraints.PAGE_END;

    config.add(bottom, c);

And currently I get the following Screenshot: enter image description here

"bottom" is by button panel. For starters, the two text fields are merged together, and the buttons should be on the bottom. Looking at the Oracle instructions on GridBagLayout didn't help too much. Any ideas?

有帮助吗?

解决方案

assuming that your class extends from JPanel then calling super(new GridBagLayout()) at the first line of your constructor may solve the issue...

Try adding this line as well c.width=GridBagConstaints.REMAINDER;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top