Results 1 to 6 of 6
  1. #1
    RLRExtra is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default Displaying text in a JTextField after pressing a button

    Having a problem with getting text to display in a text field after a button is pressed.

    I've tried useing the getText and setText but I don't think I've done it properly.

    This is what I'm useing:

    JTextField showHumanScores = new JTextField(15);

    String fieldHumanScores = showHumanScores.getText();

    fieldHumanScores.setText((humanHand[0]));

    Is this correct and my problem lies somewhere else?

    Anything to do with humanHand being an int?
    Last edited by RLRExtra; 01-17-2008 at 09:35 PM.

  2. #2
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default

    Hi RLRExtra

    Try this:
    Java Code:
    showHumanScores.setText(humanHand[0]);
    Quote Originally Posted by RLRExtra
    Java Code:
    fieldHumanScores.setText((humanHand[0]));
    I don't think that the String class has a setText() method since fieldHumanScores is an instance of String.

    Hope this helped. ;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  3. #3
    RLRExtra is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    Nope, doesn't work! :(

    When I try compile it, I get:

    in javax.swing.text.JTextComponent cannot be applied to (int)

  4. #4
    jimm1 is offline Member
    Join Date
    Jan 2008
    Location
    South Africa
    Posts
    18
    Rep Power
    0

    Default

    Is humanHand an int array?
    If so,

    try...

    showHumanScores.setText(Integer.toString(humanHand[0]));
    Last edited by jimm1; 01-17-2008 at 09:50 PM.

  5. #5
    RLRExtra is offline Member
    Join Date
    Jan 2008
    Posts
    7
    Rep Power
    0

    Default

    Nice one! It works now, thank you! :D

  6. #6
    jimm1 is offline Member
    Join Date
    Jan 2008
    Location
    South Africa
    Posts
    18
    Rep Power
    0

Similar Threads

  1. how to focus to another JTextfield?
    By birdofprey in forum AWT / Swing
    Replies: 2
    Last Post: 04-09-2008, 02:08 PM
  2. Displaying data into text area
    By abhiN in forum New To Java
    Replies: 1
    Last Post: 01-22-2008, 11:30 AM
  3. Displaying text box on MIDlet form
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-22-2007, 11:06 AM
  4. Java Next Button for displaying next row
    By susan in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 08-07-2007, 05:16 AM
  5. help with JTextfield
    By gary in forum New To Java
    Replies: 4
    Last Post: 07-11-2007, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •