在JTextPane中显示格式化的RTF

时间:2014-01-15 18:48:29

标签: java swing rtf jtextpane

我试图在JTextPane中显示RTF文件的文本,它只显示纯文本,但我需要带有粗体,字体,大小等的格式化文本...

这是代码:

public void mostraRTF() {
        RTFEditorKit rtf = new RTFEditorKit();  
        rtfDisplay.setEditorKit( rtf );  
        rtfDisplay.setBackground( Color.white ); 

        try {  
            FileInputStream fi = new FileInputStream( "F:\\31012200.rtf" );  
            rtf.read( fi, rtfDisplay.getDocument(), 0 );  
            }  
            catch( FileNotFoundException e )  
            {  
            System.out.println( "File not found" );  
            }  
            catch( IOException e )  
            {  
            System.out.println( "I/O error" );  
            }  
            catch( BadLocationException e )  
            {  
            }  

    }

0 个答案:

没有答案
相关问题