javaswingdefaultstyleddocument

How can I know the number of inserted characters by Document.insertString() method?


I am making my custom implementation of DefaultStyledDocument. And sometimes, I need to know how many characters will be (or has been) inserted by the Document.insertString() method.

But I did not find how to compute it. (The method insertString() itself can't help me as it returns void).

So is it possible to compute this value ?

Thanks in advance.


Solution

  • Can you use the length() method? i.e.:

    String s = "Example";     
    int len = s.length();