Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: add JTextField with a click of button

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    Default add JTextField with a click of button

    public class HandlerClass1 implements ActionListener
    		 	public JTextField tf1;
    			public void actionPerformed (ActionEvent event)
    				tf1 = new JTextField("");
    				tf1.setBounds(100, 80,50, 20);

    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
    Last edited by A4Andy; August 31st, 2011 at 06:11 AM.

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 632 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Lock up code to the click of a button!!!
    By Allen Walker in forum Java Theory & Questions
    Replies: 2
    Last Post: July 1st, 2011, 09:12 AM
  2. [SOLVED] Servlet cant perform sql after second button click
    By Stefan_Lam in forum What's Wrong With My Code?
    Replies: 10
    Last Post: March 31st, 2011, 05:18 AM
  3. [SOLVED] Click button to open JDialog
    By susieferrari in forum Java Theory & Questions
    Replies: 6
    Last Post: March 30th, 2011, 09:24 AM
  4. Waiting for a Second JButton Click
    By Firebert in forum Java Theory & Questions
    Replies: 0
    Last Post: March 16th, 2011, 08:15 PM
  5. close JDialog on button click
    By Christophe in forum AWT / Java Swing
    Replies: 4
    Last Post: April 4th, 2010, 11:04 PM