Mega Code Archive

 
Categories / Java by API / Javax Swing Text Rtf
 

New RTFEditorKit()

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);   } }