File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Making JTextField accept an INT?" Watch "Making JTextField accept an INT?" New topic
Author

Making JTextField accept an INT?

GregK
Greenhorn

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(String.valueOf(myInt));

or

myTextField.setText(Integer.toString(myInt));

or

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: http://aspose.com/file-tools
 
subject: Making JTextField accept an INT?