link gridbaglayout中的2个单元格

yks3o0rb  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(353)

我想在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);

但它不起作用。

x7rlezfr

x7rlezfr1#

调整你的
GridBagConstraint's weightx 以及 fill 使组件沿x轴展开:

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

相关问题