Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

Problem using JTextPane

Thread view: 
Dotanitis@gmail.com - 10 Apr 2007 12:32 GMT
Hello to all,

I'm trying to build a simple consule. currently i'm building the
window and initial text.when the user will press Enter, the prompt
will display (after jumping to newline) again. The way that i
implement it: i'm using a listener and when the add event invoked & i
see that the user add the Enter char (10) the system "know" that it
should display prompt using my function showPrompt(); BUT here is the
problem, i've got an exception which tells me that i cannot modify the
view in an event.(somthing about view-lock).

so my questions are:
1. how you will suggest me to implement this tast (displaying the
prompt after pressing the enter key).
2. If you know about similar problam that have an implementation on
web, send me the URL address,pls.

Thanks!
Dotan.
Andrew Thompson - 10 Apr 2007 12:37 GMT
..
>...BUT here is the
>problem, i've got an exception which tells me that i cannot modify the
>view in an event.(somthing about view-lock).

I suggest..
1) always <http://www.physci.org/codes/javafaq.html#exact>
2) make/post <http://www.physci.org/codes/sscce.html>

Signature

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

Dotanitis@gmail.com - 10 Apr 2007 16:55 GMT
> Dotani...@gmail.com wrote:
>
[quoted text clipped - 12 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200704/1

well.. you did'nt help me :(
Joshua Cranmer - 10 Apr 2007 22:36 GMT
>> Dotani...@gmail.com wrote:
>>
[quoted text clipped - 13 lines]
>
> well.. you did'nt help me :(

That's because you didn't provide enough information for him to make an
attempt at solving the problem.

You've done the newsgroup equivalent of going up to a marriage counselor
and asking, "I have a marriage problem. How can I save my marriage?"

Specifically, we want to know the exact exception you getting
(copy/paste the exception + trace), and copies of the code which are
relevant.
Dotanitis@gmail.com - 11 Apr 2007 07:45 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.