简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM