Solved

Problem replacing DefaultStyledDocument with HTMLDocument in an Application

Posted on 2003-12-04
8
459 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
ID: 9874312
Are you sure the HTMLDocument you created is being used and not one got from the kit?
0
 
LVL 3

Expert Comment

by:savalou
ID: 9874369
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
ID: 9874420
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Accepted Solution

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

Expert Comment

by:objects
ID: 9876991
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
ID: 11662557
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
ID: 11665365
8-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 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

13 Experts available now in Live!

Get 1:1 Help Now