On Apr 11, 12:36 am, Joshua Cranmer <Pidgeo...@epenguin.zzn.com>
wrote:
> Dotani...@gmail.com wrote:
> >> Dotani...@gmail.com wrote:
[quoted text clipped - 24 lines]
> (copy/paste the exception + trace), and copies of the code which are
> relevant.
I see. Thank you Joshua Cranmer, I'll do my best this time:
I'm trying to build a console using JTextpane:
my main classes are DBShell which extend JFrame and DbShellFilter
which extends DocumentFilter (which i'll use to limit the size of my
documnet (AbstructDocumnet interface)
I've got 2 main members : JTextPane textPane & AbstactDocumnet doc
I init the doc by:
StyledDocument styleDoc = textPane.getStyledDocument();
if (styleDoc instanceof AbstractDocument)
{
doc = (AbstractDocument) styleDoc;
doc.setDocumentFilter(new DbShellFilter(MAX_CHAR));
}
else
{
// invoke an error message
System.err.println("Text Plane's Document isn't an
AbstractDocument");
System.exit(-1);
}
Here is the main troublemaker:
i'm adding to the doc a listener:
doc.addDocumentListener(new MyDocumentListener());
and the problem when i implement the MyDocumentListener (extends
DocumentListener)
protected class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
textPane.setText("hi"); // HERE I'll got an exception*;
}
* Exception in thread "AWT-EventQueue-0"
java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
at javax.swing.text.AbstractDocument.remove(Unknown Source)
at javax.swing.JEditorPane.setText(Unknown Source)
at DbShell.handleText(DbShell.java:118)
at DbShell$MyDocumentListener.displayEditInfo(DbShell.java:101)
at DbShell$MyDocumentListener.insertUpdate(DbShell.java:80)
at javax.swing.text.AbstractDocument.fireInsertUpdate(Unknown Source)
at javax.swing.text.AbstractDocument.handleInsertString(Unknown
Source)
at javax.swing.text.AbstractDocument
$DefaultFilterBypass.replace(Unknown Source)
at javax.swing.text.DocumentFilter.replace(Unknown Source)
at DbShellFilter.replace(DbShellFilter.java:43)
at javax.swing.text.AbstractDocument.replace(Unknown Source)
at javax.swing.JTextPane.replaceSelection(Unknown Source)
at javax.swing.JTextPane.replaceSelection(Unknown Source)
at javax.swing.text.DefaultEditorKit
$DefaultKeyTypedAction.actionPerformed(Unknown Source)
at javax.swing.SwingUtilities.notifyAction(Unknown Source)
at javax.swing.JComponent.processKeyBinding(Unknown Source)
at javax.swing.JComponent.processKeyBindings(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown
Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown
Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown
Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Thanks
Dotan
Andrew Thompson - 11 Apr 2007 11:26 GMT
..
>* Exception in thread "AWT-EventQueue-0"
>java.lang.IllegalStateException: Attempt to mutate in notification
OK - we are now part way to what I suggested.
Some folks may be clever enough to spot the
problem based upon the code snippets posted
above, but the problem might not be with those
parts of the code, so I still recommend posting
an SSCCE.
If you post an SSCCE, I will look further at the
problem (and probably so will other people).

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Nicolai - 11 Apr 2007 13:15 GMT
On 11 Apr., 08:45, "Dotani...@gmail.com" <Dotani...@gmail.com> wrote:
> On Apr 11, 12:36 am, Joshua Cranmer <Pidgeo...@epenguin.zzn.com>
> wrote:
[quoted text clipped - 119 lines]
>
> Dotan
>From the DocumentListener API:
The DocumentEvent notification is based upon the JavaBeans event
model. There is no guarantee about the order of delivery to listeners,
and all listeners must be notified prior to making further mutations
to the Document. *This means implementations of the DocumentListener
may not mutate the source of the event (i.e. the associated
Document).*
...
And here
protected class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
textPane.setText("hi"); // HERE I'll got an
exception*;
}
you try to change the associated Textpane-Document whithin the Event-
processing.
Dotanitis@gmail.com - 11 Apr 2007 15:12 GMT
> On 11 Apr., 08:45, "Dotani...@gmail.com" <Dotani...@gmail.com> wrote:
>
[quoted text clipped - 140 lines]
> you try to change the associated Textpane-Document whithin the Event-
> processing.
Thanks. I'm understand that i cannot make change while the event is
happened. So how can I implement an text insertion after the event was
call?
Andrew Thompson - 11 Apr 2007 15:24 GMT
>...how can I implement an text insertion after the event was call?
<http://java.sun.com/javase/6/docs/api/javax/swing/SwingUtilities.html#invokeLate
r(java.lang.Runnable
)>

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Dotanitis@gmail.com - 12 Apr 2007 11:59 GMT
> Dotani...@gmail.com wrote:
> >...how can I implement an text insertion after the event was call?
[quoted text clipped - 6 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1
Thanks i'll read it. I till try to SSCCE because I'm really understand
that this is the right way (as you written in the documnet), to
preform a problem in a discussion group. ... well it's not easy...
Andrew Thompson - 12 Apr 2007 13:53 GMT
...
>Thanks i'll read it. I till try to SSCCE because I'm really understand
>that this is the right way ..
Well, I never (that I remember) said it was the 'right'
way - but it *can* be extremely helpful to solving a
problem, or communicating a problem to others.

Signature
Andrew Thompson
http://www.athompson.info/andrew/