Hi,
To load a RTF-document, I tried to use an JEditorPane and
invoke the read(Reader,null) method of
com.sun.java.swing.text.rtf.RTFEditorKit.

But there is allways a problem filtering using the RTF-Filter:
--- output of my little program: -------
reading charset ansi
Exception loading RTF character set "ansi": java.io.IOException: Unable
to read from character set file (java.lang.NullPointerException: )
Unknown RTF character set "ansi"
Unknown keyword: deff (param 0)
Done reading font table.
Number 1: helvetica
Number 0: Times New Roman

Done reading color table, 3 entries.
Unknown keyword: keepn
Unknown keyword: keepn
Warning, RTF destination overridden, invalid RTF.
Canīt read from file: java.lang.NullPointerException: 
--- End of output ----

In the attachment I added a litle demo programm an a two-lines demo
rtf-file.

Thank you for any help,

Bernhard
// ---- test program to demonstrate the Problems with JEditorPane and RTF-Text ---
import com.sun.java.swing.*;
import com.sun.java.swing.text.*;
import com.sun.java.swing.text.rtf.*;

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class RTFTest extends JFrame{
  JEditorPane rtfPane;
  RTFEditorKit rtfEditorKit;
  Document rtfDoc;
  public static String docName="test2.rtf";

  public RTFTest(String title){
    super(title);
    rtfPane = new JEditorPane();
    rtfEditorKit=new RTFEditorKit();
    rtfPane.setEditorKit(rtfEditorKit);
    rtfDoc=rtfEditorKit.createDefaultDocument();
    try{
      rtfEditorKit.read(new FileInputStream(docName),rtfDoc,0);
    } catch (Exception e) {
      System.err.println("Canīt read from file: "+e);
    }
    getContentPane().add(rtfPane, BorderLayout.CENTER);
  }

  public static void main(String args[])
  {
    RTFTest testFrame = new RTFTest("Test für RTF-Dokumente");
    testFrame.addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        System.exit(0);
      }
    });
    testFrame.setSize(500,500);
    testFrame.setVisible(true);
  }// main

}





test2.rtf

Reply via email to