I have a form to add a text box to GridBagLayout. Is it possible that each addition of a text field, the field will have a different name for the variable? Because now every time adds the same name, but different x, y I was thinking to create a static field as a counter to be added to the variable name, but I do not know how to add this number to the name.
Here is my code:
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);