This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes IllegalStateException in a StyledDocument Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "IllegalStateException in a StyledDocument" Watch "IllegalStateException in a StyledDocument" New topic
Author

IllegalStateException in a StyledDocument

Rey Fernandez
Greenhorn

Joined: Aug 06, 2009
Posts: 10
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?
Rey Fernandez
Greenhorn

Joined: Aug 06, 2009
Posts: 10
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?
Alan Mehio
Ranch Hand

Joined: Apr 04, 2005
Posts: 73
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.

Please take a look at
This


Regards,
Alan Mehio
London, UK
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2153
    
    7
Use a DocumentFilter. An example can be found in the section from the Swing tutorial on "Text Component Features".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: IllegalStateException in a StyledDocument
 
Similar Threads
JTextPane , StyledDocument
Displaying lines with multiple colors
Find index by xy ??
StyleAttributes not applying when called in quick succession
Issue in "Styling" JTextPane