Solved

Problem replacing DefaultStyledDocument with HTMLDocument in an Application

Posted on 2003-12-04
8
455 Views
Last Modified: 2008-02-01
Hi experts,

I'm trying to modify an application that uses JTextPane and DefaultStyledDocuments to implement an Editor.

I need to change the Documenttype from javax.swing.text.DefaultStyledDocument to
javax.swing.text.html.HTMLDocument in order to enhance the editor functionality.

As the documents that we want to edit are not being stored in files on a filesystem, but rather as a set of records in a database, we had to create a new kind of Document which now extends from the DefaultStyledDocument. so far so good ... everything works fine.

when i type a character the method "insertString(int offset, String str, AttributeSet a)" is being called, which we overload with our own database version, that calls the "super.insertString(...)" as well.

now when i change the DefaultStyledDocument to a HTMLDocument everything still works (more or less) .... then when i change the EditorKit to a HTMLEditorKit, the insertString(int offset, String str, AttributeSet a)"-Method is not being called anymore.

Typed text is still being inserted into the text area.... but our database-methods are no longer being called, as they are in the "insertString(...)"-Method that is never called anymore.

now my question : which method IS being called when i type a letter?? which method do i need to rewrite in order to hook my database calls in again everytime a letter is typed?

thanx for your help.

dominik

PS if this turn's out to be real tough one, i'm willing to increase points too.
0
Comment
Question by:dom_bus
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Are you sure the HTMLDocument you created is being used and not one got from the kit?
0
 
LVL 3

Expert Comment

by:savalou
Comment Utility
Maybe you should derive from HTMLEditorKit to override the createDefaultDocument() method (if that's how you are creating your document, but also to test whether it's being called).  You could also then override insertHTML() to see what's going on.  Trace the calls in a debugger.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Make sure the same relationships are preserved as in the following:

   JEditorPane ep = new JEditorPane();
   ep.setContentType("text/html");
   getContentPane().add(ep);
   MyDoc myDoc = new MyDoc();
   ep.setDocument(myDoc);
   EditorKit kit = ep.getEditorKit();
   try {
         kit.read(new StringReader("<HTML><BODY>Type in some text<BR></BODY></HTML>"), myDoc, 0);
   }
   catch(Exception e) {
         e.printStackTrace();
   }


................


class MyDoc extends HTMLDocument {
      public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
            System.out.println("Called insertStr!");
                super.insertString(offset, str, a);
        }
}

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
Comment Utility
(i.e. the relationship between doc, kit and pane). The above works fine for me.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
can you post the relevant parts of your code and we'll help sort out what your problems are.
0
 

Author Comment

by:dom_bus
Comment Utility
sorry for not accepting this answer (together with the above post of CEHJ) earlier.

lost track of it as soon i finally had this and some other problems solved.

best regards & thanx again.

dom_bus
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
8-)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now