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 Beginning Java and the fly likes Making JTextField accept an INT? 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 » Beginning Java
Bookmark "Making JTextField accept an INT?" Watch "Making JTextField accept an INT?" New topic

Making JTextField accept an INT?


Joined: Oct 24, 2005
Posts: 15
Is this possible?

I'm trying to use the set text method to put an integer value in a JTextField and getting the incompatibility error, is this possible or is there another method I'm not aware of?
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
you could use:





myTextField.setText("" + myInt);

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
You can use String.valueof(integer), or use java.text.DecimalFormat's format method if you want commas added: 12,333 etc...

There is no emoticon for what I am feeling!
I agree. Here's the link:
subject: Making JTextField accept an INT?
Similar Threads
Setting hot keys
Setting Up a JTextField to only accept Integers - Solution! (with Questions)
length of a jtextfield
Which data structure is best suited for this?
cloning swing components