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;
题
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:
"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;