我想在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);
但它没有用。
答案 0 :(得分:1)
调整您的GridBagConstraint's
weightx
和fill
,使组件沿x轴展开:
gridBagConstraints.weightx = 1;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;