user3104624
user3104624

Reputation: 33

Add JTextField dynamically - Java

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.

Upvotes: 1

Views: 438

Answers (1)

trashgod
trashgod

Reputation: 205885

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

Upvotes: 2

Related Questions