我有一个向 GridBagLayout 添加文本框的表单。是否有可能每次添加一个文本字段,该字段都会有不同的变量名称?因为现在每次都加同一个名字,但是不同的x,y 本来想创建一个静态字段作为计数器加到变量名上,但是不知道怎么把这个数字加到名字上。
这是我的代码:
JTextArea dodawanyTextField = new javax.swing.JTextArea();
dodawanyTextField.setText(nazwaLekcjiTextField.getText());
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.weighty = 1;
gridBagConstraints.fill = GridBagConstraints.VERTICAL;
//gridBagConstraints.gridheight = 100;
gridBagConstraints.gridheight = ileGodzinLekcji;
gridBagConstraints.gridx = dzienLekcji;
gridBagConstraints.gridy = godzinaLekcji;
if (wykladRadioButton.isSelected()) {
dodawanyTextField.setBackground(new java.awt.Color(245, 184, 0));
} else if (cwiczeniaRadioButton.isSelected()) {
dodawanyTextField.setBackground(new java.awt.Color(61, 245, 0));
} else if (laboratoriumRadioButton.isSelected()) {
dodawanyTextField.setBackground(new java.awt.Color(0, 184, 245));
}
dodawanyTextField.setMaximumSize(new java.awt.Dimension(125, 800));
dodawanyTextField.setPreferredSize(new java.awt.Dimension(125, 50));
dodawanyTextField.setWrapStyleWord(true);
dodawanyTextField.setLineWrap(true);
jPanel3.add(dodawanyTextField, gridBagConstraints);