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: JTextField with JButtons

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Thanked 0 Times in 0 Posts

    Default JTextField with JButtons

    How do you append to a JTextField with a JButton without the previous text being deleted

    for example if i had
    JButton num0 = new JButton("0")
    JButton num1 = new JButton("1")
    JTextField text = new JTextField()


    public void actionPerfomed(ActionEvent e){
    Object source = e.getSource()

    if(source == num0)

    if(source == num1)


    i would like the textfield to say if 0 then 1 is pressed - 01
    but instead it will do 0 then when 1 is pressed 0 is erased and 1 is in the textfield
    any help would be appreciated

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

    Default Re: JTextField with JButtons

    Hint: JTextField has a method called getText() that you can use to get the String already displayed.
    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. How to add Image to my JButtons?
    By sim18 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: November 26th, 2012, 02:35 PM
  2. Java Connect to MySQL using jTextfield, jbuttons in NetBeans
    By Light Mike in forum JDBC & Databases
    Replies: 2
    Last Post: August 11th, 2012, 10:41 PM
  3. JButtons not showing
    By Shaybay92 in forum AWT / Java Swing
    Replies: 1
    Last Post: September 27th, 2011, 07:42 AM
  4. Adding JButtons to Frame
    By iKlaush in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 12th, 2011, 10:52 AM
  5. help with JFrame, drawing, and JButtons
    By Khoatic in forum AWT / Java Swing
    Replies: 1
    Last Post: November 19th, 2010, 12:34 AM