`
zengxx1989
  • 浏览: 294974 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

JEditorPane显示HTML中文乱码

阅读更多
import javax.swing.JEditorPane;  import javax.swing.JFrame;  import javax.swing.JScrollPane;  import javax.swing.ScrollPaneConstants;    public class ScratchPad {      public static void main(String args[]) throws Exception {          String html ="<html>"+  "<head>"+  "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/>"+ // this is the problem right here  "<title>Error 400 BAD_REQUEST</title>"+  "</head>"+  "<body>"+  "<h2>HTTP ERROR: 400</h2><pre>BAD_REQUEST</pre>"+  "<p>RequestURI=null</p>"+  "<p><i><small><a href=\"http://jetty.mortbay.org\">Powered by jetty://</a></small></i></p>"+  "</body>"+  "</html>";          JFrame f = new JFrame();          JEditorPane editor = new JEditorPane();          editor.setEditable( false );          editor.getDocument().putProperty( "Ignore-Charset", "true" );  // this line makes no difference either way          editor.setContentType( "text/html" );          editor.setText( html );          f.add( new JScrollPane(editor, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,                                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) );          f.pack();          f.setVisible( true );      }  }  


JEditorPane.setContentType("text/html;charset=utf-8");
分享到:
评论
1 楼 lliiqiang 2014-07-18  
枚举类型可以在父类中根据instanceof强制判断是否是指定类型,否则抛出异常,阻止创建对象,不过像数据校验的应该允许在父类调用方法之前被调用,包括单纯配置set属性,当然不能访问当前类属性和直接访问属性方法,因为对象未正常初始化.

相关推荐

Global site tag (gtag.js) - Google Analytics