File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Integers and Textfields." Watch "Integers and Textfields." New topic

Integers and Textfields.

mark geroso

Joined: Oct 12, 2006
Posts: 24
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

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

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:
subject: Integers and Textfields.
It's not a secret anymore!