问题
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.
回答1:
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().
回答2:
you can use the length function in the Text of the jTextArea like this
jTextField.getText().length()
来源:https://stackoverflow.com/questions/30582795/how-to-get-the-number-of-character-in-a-jtextarea