add JTextField with a click of button
Code :
public class HandlerClass1 implements ActionListener
{
public JTextField tf1;
public void actionPerformed (ActionEvent event)
{
tf1 = new JTextField("");
tf1.setBounds(100, 80,50, 20);
add(tf1);
}
}
What I want the program to do is if a user click the button it will add a new JTextField. My codes return no error or anything. My Program started with no textfield.
I just added a space between the quotation marks and it works
Re: add JTextField with a click of button
You can't just add components to an already visible GUI. You have to revalidate the container in question- check out the API for useful functions.