Baldráni
Baldráni

Reputation: 5640

How to get the number of character in a JTextArea?

I have a JTextArea and I need to take each one of the field's characters to translate it into another. But for this purpose I need to browse in the JTextArea.

So I thought of a simple loop like:

for(int i = 0; i <= t.length(); i++) { ... }

but the length() function is not appropriate and I can't find one which is.

If anyone has already encountered this problem, I'd like a bit of help with it.

Upvotes: 2

Views: 3970

Answers (2)

Alex Lord Mordor
Alex Lord Mordor

Reputation: 3040

you can use the length function in the Text of the jTextArea like this

jTextField.getText().length()

Upvotes: 2

uraimo
uraimo

Reputation: 19791

If you need the String content of a JTextArea field just use textArea.getText(), and then use that string as you usually do, e.g. getting its length with length().

Upvotes: 3

Related Questions