is there any alternative for this code to run without exception?
The above code will launch a JFrame with a JTextPane on it, but it generates an IllegalStateException upon inserting a string to the JTextPane. My goal is to make the program react to the change in the JTextPane's document and this reaction to the change is by inserting a String to the same document where the event came from.Is there any other way to accomplish this task?
Joined: Aug 06, 2009
if the cause of is exception is the possible infinite invocation of the DocumentListener, is there a way where only text changes can be listened not font color, size or any other changes only the textcontent of the document will be listened?
Joined: Apr 04, 2005
Rey Fernandez wrote:is there any alternative for this code to run without exception?
Document listeners shouldn't modify the contents of the document; The change is already complete by the time the listener is notified of the change
Your situation violates the bean event model where order of delivery is not guaranteed and all listeners should be notified before further mutations are allowed.
In your case, you are trying to mutate the document and still there are some listeners has not been notified. Simply, you try to triggers update inside an update.
The document has been update and you get the update; so simple display the updat in different place.