在GridBagLayout中链接2个单元格

时间:2013-06-05 21:47:40

标签: java swing gridbaglayout

我想在GridBagLayout中链接2个单元格。 我使用Netbeans,所以我用JAppletForm编写。

JTextField dodawanyTextField = new javax.swing.JTextField();

dodawanyTextField.setText(nazwaLekcjiTextField.getText());

gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;

jPanel3.add(dodawanyTextField, gridBagConstraints);

但它没有用。

1 个答案:

答案 0 :(得分:1)

调整您的GridBagConstraint's weightxfill,使组件沿x轴展开:

gridBagConstraints.weightx = 1;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;