日期:2014-05-20  浏览次数:20938 次

用JEditorPane显示rtf文档,有中文时出现乱码,求教。
如题:
用word新建一个空文档,输入一排英中文混排的文字,另存为rtf文件:c:\test.rtf。


JEditorPane   jEditorPane1   =   new   JEditorPane();  
jEditorPane1.setContentType( "text/rtf ");  
File   file   =   new   File   ( "c:/test.rtf ");
String   str   =   file.getAbsolutePath();
str   =   "file: "+str;
jEditorPane1.setPage(str);
jEditorPane1.setEditable(false);
JFrame   jframe   =   new   JFrame( "test ");
jframe.setContentPane(jEditorPane1);
jframe.setBounds(0,0,100,100);
jframe.setVisible(true);

显示出来的英文字符正确,中文乱码。

------解决方案--------------------
出现乱码啊,应该是字符集的问题.你设置一下encode,比如设置成utf-8
------解决方案--------------------
你试过其他的字符集没?除了gb2312之外的
------解决方案--------------------
this.richTextBox1.Rtf = @ "{\rtf1\ansi\ansicpg936 dajiahao: 13:11:40 "+ @ "\par 文章 } ";

这个rtf可以正常显示中文
------解决方案--------------------
936 在这里代表rtf的简体中文字符集