JDK-4485900 : Cannot display embedded image in an RTF file
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-07-30
  • Updated: 2015-10-16
Related Reports
Relates :  
Description

Name: bsC130419			Date: 07/30/2001


java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

Unable to view an RTF file which has an embedded image in it. Only the text
appears.
1. A java UI application extending JFrame, embeds a JTextPane instance.
2. instance of RTFEditorKit is set as the editor kit for JTextPane
3. An RTF File which has an embedded image in it is read. Default styled
document is used to set the style of the RTFEditorKit instance

Sample code is enclosed below. This requires an test.rtf file in the directory
where the class file resides which contains an embedded jpeg image in it





/**
 * Sample code
 */
import java.awt.*;
import java.io.InputStream;
import java.io.FileInputStream;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.rtf.*;



public class RTFFrame extends JFrame {
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  JTextPane m_monitor = new JTextPane();

  StyleContext m_context;

  DefaultStyledDocument m_doc;

  RTFEditorKit m_kit;


  /**Construct the frame*/
  public RTFFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception  {

    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(600, 450));
    this.setTitle("");
    contentPane.add(m_monitor,  BorderLayout.CENTER);

    m_kit = new RTFEditorKit();
    m_monitor.setEditorKit(m_kit);
    m_context = new StyleContext();


    try {

        InputStream in = new FileInputStream(".\\test.rtf");
        m_doc = new DefaultStyledDocument(m_context);
        m_kit.read(in, m_doc, 0);
        m_monitor.setDocument(m_doc);
        in.close();

    }

    catch (Exception ex) {

         ex.printStackTrace();

    }

}
  /**Overridden so we can exit when window is closed*/
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

    public static void main(String[] args) {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e) {
      e.printStackTrace();
    }
    RTFFrame frame = new RTFFrame();
    frame.setVisible(true);

  }



}
(Review ID: 128992) 
======================================================================