Avoid DocumentFilter being called when value is set programatically

64 Views Asked by At

I have a DocumentFilter installed on a Document attached to JTextArea. The purpose of the filter is to handle and filter changes made by the user, and when they are detected, to update another (graphical) view of the document based on the document content (the document is a textual representation of the desired graphics).

I have a little problem of the filter to be called also when I perform setText on the JTextArea. In this situation I would like the filter not to be processed, as the input is not coming from the user, and the document is already known, the graphical view loaded and it is not necessary to load it again. I see some trivial options how to prevent it, but they all smell to me:

  • create a global Boolean variable telling the filter to suppress itself
  • disable the filter before the setText call and install it again once it is finished

I guess there must be some nicer way. Any advice?

0

There are 0 best solutions below