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?
Asked
Active
Viewed 628 times
5

Paul Samsotha
- 205,037
- 37
- 486
- 720

Aviv Cohn
- 15,543
- 25
- 68
- 131
-
What do you mean "why that is"? – Invictus May 07 '14 at 18:31
1 Answers
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 to a replace and then let the replace logic check to see if remove/insert is required.

camickr
- 321,443
- 19
- 166
- 288