Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making JTextField accept an INT?

 
GregK
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you could use:

myTextField.setText(String.valueOf(myInt));

or

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

or

myTextField.setText("" + myInt);
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use String.valueof(integer), or use java.text.DecimalFormat's format method if you want commas added: 12,333 etc...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic