How to get the number of character in a JTextArea?

*爱你&永不变心* 提交于 2019-12-14 03:51:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!