문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top