Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IllegalStateException in a StyledDocument

 
Rey Fernandez
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Camick
Ranch Hand
Posts: 2475
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a DocumentFilter. An example can be found in the section from the Swing tutorial on "Text Component Features".
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic