Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting string to an int

0 views
Skip to first unread message

Jordi Maycas

unread,
Dec 27, 2002, 9:47:19 AM12/27/02
to
How can I convert the text in a jTextPane to an integer value?


Peter van der Goes

unread,
Dec 27, 2002, 11:02:23 AM12/27/02
to
In generic Java, you can convert a string in a text field to an integer
using something like this:

int myInt = (Integer.parseInt(jtextfield1.getText().trim()));

As there is a getText() method available to the jTextPane class via
inheritance, you should be able to use a similar technique.
There's a fair amount going on here: The trim() method removes any leading
and trailing spaces from the string in the object, then the trimmed text is
returned and used as the argument to the parseInt() method, which will
convert the string to an integer using standard Java conversion rules and
store the result in myInt.
HTH!

"Jordi Maycas" <come...@todo-pc.com> wrote in message
news:3e0c67ec$1...@newsgroups.borland.com...

Peter van der Goes

unread,
Dec 27, 2002, 11:24:57 AM12/27/02
to
Doh!
I misspoke in the explanation.
The trim() method operates on the text returned by the getText() method -
not before the getText() method, before the parseInt() method executes.

"Peter van der Goes" <pv...@nospam.att.net> wrote in message
news:3e0c...@newsgroups.borland.com...

Jordi Maycas

unread,
Dec 28, 2002, 1:01:48 PM12/28/02
to
Thanks Peter

And Merry Christmas & Happy New Year.

"Peter van der Goes" <pv...@nospam.att.net> escribió en el mensaje
news:3e0c7eba$1...@newsgroups.borland.com...

0 new messages