This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "getting the text " Watch "getting the text " New topic
Author

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?
Thanks
ben
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
ben
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ben,
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getting the text