DocumentFilter: Why is replace() invoked and not insertString()?
Asked Answered
B

1

5

I've implemented a DocumentFilter subclass, and when I type text into the JTextComponent, the replace() method of the filter is invoked, and not insertString() (which is never invoked). Any idea why that is?

Burchell answered 7/5, 2014 at 18:25 Comment(1)
What do you mean "why that is"?Kieger
C
7

The insertString(...) method is invoked when you update the Document directly, by using the Document.insertString(...) method.

The replace(...) method is invoked when the Document is updated by methods of the View (ie. the JTextField) when the user enters text or the user invokes Actions (cut, paste) associated with the text field.

I guess its is easier to always do a replace and then let the replace logic check to see if remove/insert is required.

Cuvette answered 7/5, 2014 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.