Java by API/javax.swing.text.rtf/RTFEditorKit — различия между версиями
Admin (обсуждение | вклад) м (1 версия)  | 
				Admin (обсуждение | вклад)  м (1 версия)  | 
				
(нет различий) 
 | |
Текущая версия на 14:31, 31 мая 2010
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);
  }
}
   
   
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);
  }
}