From the Swing tutorial on text components:
You may want to change the document\'s text within a document listener. However, you should never modify t
The text say's that you may want to use a document listener. Here is a example how to write one.
A Swing text component uses a Document to represent its content. Document events occur when the content of a document changes in any way.
So, always that your text component changes the document listener will fire, but the text says that you cannot change the value of the component in this listener.
In a KeyListener
(that's not a document listener) you can change the value using setText()
.
Depending on what you want, i suggest you look DocumentFilter.