我想在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);
但这是行不通的。
最佳答案
调整GridBagConstraint's
weightx
和fill
,以使组件沿x轴扩展:
gridBagConstraints.weightx = 1;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;