wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Integers and Textfields. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Integers and Textfields." Watch "Integers and Textfields." New topic
Author

Integers and Textfields.

mark geroso
Greenhorn

Joined: Oct 12, 2006
Posts: 24
Hi.
How do I make an integer value show up in a textfield? Certain user actions can increment the integer value, I'd also like the integer in the textfield to update...
Parth Bhatt
Ranch Hand

Joined: Oct 19, 2005
Posts: 58
Hi,

The value that you read from the textfield will always be a string. And to increment the value read you will always need an int.

So in this case The obvious solution would be : Whenever you want to increment the contents of the text field,

1)read it into a string


2)Convert it into an int


3)Put the new incremented value into the textfield


NOTE : In step (2) if the contents of the textfield is not integer, it will throw a NumberFormatException. So beter handle it.


If your new Big Idea doesn't scare the hell out of you, <br />it's probably not a "new Big Idea".
mark geroso
Greenhorn

Joined: Oct 12, 2006
Posts: 24
Thanks. I kept getting tripped up because the value wasn't updating, didn't think about extracting the value from the textfield first.
I'll give it a try.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Integers and Textfields.
 
Similar Threads
how to check string or int?
TextField to the Applet
JTextField
Hi guys !! I really need your help here ..
This is really bad => How to add a combobox to an existing textfield dynamically