This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes getting the text Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting the text " Watch "getting the text " New topic

getting the text

ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Hello all,
I have a int called num which holds the number 10 in it, and I want my text field to display the ints value.
I have tried this:

what am I doing wrong?
Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
Try :
ivjJTextField4.setText( String.valueOf( num ) );
ben riches
Ranch Hand

Joined: Nov 08, 2002
Posts: 126
Originally posted by Don Kiddick:
Try :
ivjJTextField4.setText( String.valueOf( num ) );

Thanks Don that has worked fine
Thanks agian
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299

Just to elaborate a bit on what Don posted, the Java API is your friend.
If you look at the API for JTextField you will notice that the method setText() takes a String as an argument. You tried to pass it an int, hence, the compilation error. Also, look closely at compliation errors. They are pretty good, though not always, about telling you what the problem is.
I only say all this because it can save you a tremendous amount of time waiting for people to reply to your posts. I also say this because I wasn't sure if you knew the reason WHY what you were doing didn't work.
I am imfamous for just getting things to work and not caring WHY it works or didn't work. After 4 years of Java programming, I am now trying to break that habit and learn more about WHY than just accepting that things work.

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: getting the text
Similar Threads
Finding the largest Prime Factor
postfix and prefix increment precedence in conditional expressions
JTextField not repainting itself when asked
Struts and javascript
prime numbers -please help