RTFEditorKit: read(InputStream in, Document doc, int pos) : RTFEditorKit « javax.swing.text.rtf « Java by API






RTFEditorKit: read(InputStream in, Document doc, int pos)

  

import java.awt.BorderLayout;
import java.io.FileInputStream;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.text.rtf.RTFEditorKit;

public class Main extends JFrame {
  public Main() throws Exception{
    setSize(400, 240);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    getContentPane().add(topPanel, BorderLayout.CENTER);

    RTFEditorKit rtf = new RTFEditorKit();
    JEditorPane editor = new JEditorPane();
    editor.setEditorKit(rtf);

    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(editor);
    topPanel.add(scroller, BorderLayout.CENTER);

    FileInputStream fi = new FileInputStream("test.rtf");
    rtf.read(fi, editor.getDocument(), 0);
  }

  public static void main(String args[]) throws Exception{
    Main mainFrame = new Main();
    mainFrame.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.new RTFEditorKit()