can you show the code where that exception is thrown?
stultuske
Industrious Poster
4,489 posts since Jan 2007
Reputation Points: 1,377
Solved Threads: 627
Skill Endorsements: 25
The problem seems to be that the document is locked when the listener is called, so when you try to update the document you can't get the lock to write to it. The solution, if you want to keep it working the same way, is to use SwingUtilities.invokeLater to run the update after your listener has finished.
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
Look at all the places where you try to change the contents and replace the remove or add statements with an invokeLater that runs the remove or add later.
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
By updating the document you are triggering your listener - which updates the document - ...
One way to avoid this is to have a shared boolean that you set when you do a programmatic update (ie in the invokeLater's run) then test this in the document listener to decide whether to do anything (and, of course, reset the boolean).
(I'm going offline now, so you may need some trial-and-error to get it right.)
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
i'm not getting the result
What result are you not getting? What code did you write?
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
So you haven't tried to implement what I suggested?
OK.
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33
Your while loop in run1 will never terminate, so your code is stuck in an infinite loop.
Your document listener will be called when the document changes. This may be because the user has typed something, or becuase your code has changed it. If the user has changed it you want to perform yopur updates, but not in response to your code changing it.
So you need a shared boolean.
When you update the document (ie in your run1 class) you set the boolean to show that this is a programmatic change, not a user change.
When you respond to changes you check the boolean. If it's fase then you are responding to user input and can continue as normal. If it;s true you are responding to a programmed change, and don't want to do anything else (except reset the boolean).
JamesCherrill
... trying to help
8,666 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,476
Skill Endorsements: 33