Clarification on modifying a Document's contents from a DocumentListener

后端 未结 3 480

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

3条回答
  •  一生所求
    2020-12-21 23:03

    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.

提交回复
热议问题