Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextField listener when text changes that modifies textField's text

Any idea how I can add a text listener on to a JTextField, that triggers when the text changes and as an action modifies the JTextField's text.

I have tried using addInputMethodListener which seems to be appropriate but it doesn't seem to work. I have also tried textField.getDocument().addDocumentListener() but this throws java.lang.IllegalStateException: Attempt to mutate in notification when I try to modify textField's text.

like image 885
Random42 Avatar asked Jul 24 '26 17:07

Random42


1 Answers

DocumentListeners do not permit the modification of the underlying document of the JTextComponent. You are looking for a DocumentFilter.

Example

like image 110
Reimeus Avatar answered Jul 26 '26 06:07

Reimeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!