1

Into textfield i set the value (how many create components)

i have button:

    JButton DoIt = new JButton("DoIt");
            DoIt.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {

                   newComp(textField.getText());
                }
            });

public static void newComp(String value)
    {
        for(int i=0;i<Integer.parseInt(value);i++)
        {       

            panel.add(new JTextField( 5));
            panel.revalidate();
            panel.repaint();
    }

How to identify components (name) when i set into textfield value: 4 and click on button? i Got 4 new components but i will use it to next step and i dont know how i will use method getText() to this.

mKorbel
  • 109,525
  • 20
  • 134
  • 319

1 Answers1

2

When you add new components, also add them to a List<JTextField> for later reference. This example shows a List<JFormattedTextField>.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045