Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem replacing DefaultStyledDocument with HTMLDocument in an Application

Posted on 2003-12-04
8
Medium Priority
?
469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

604 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