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");
分享到:
相关推荐
java写的html浏览器。只有最基本的功能哦
NetBeans项目文件 博文链接:https://bps.iteye.com/blog/136627
NULL 博文链接:https://gh0769.iteye.com/blog/598839
这个资源里有两个拖拽功能,一个把文件内容拖入JEditorPane一个是将文件路径拖入swing控件,实现swing对文件的拖拽
使用html2canvas技术将html页面转换为图片
Swing盒SwingBox是Java Swing组件,它允许显示(X)HTML文档,包括CSS支持。 它被设计为JEditorPane的替代品,具有更好的渲染结果。 SwingBox是纯Java语言,它使用CSSBox渲染引擎来渲染文档。 有关更多信息和下载,...
创建PDF文件,可由HTML代码生成PDF文件
jdic JEditorPane两种方式的WEB浏览器,比较简单。
Java网络编程(第三版)中文版(不看后悔) JAVA Network Programming,Third Edition 原出版社: O'Reilly 作者: (美)Elliotte Rusty Harold [作译者介绍] 译者: 朱涛江[同译者作品] 林剑 丛书名: O'...
支持HTML和HTM页面的显示. 使用了JEditorPane组件 * 运行时仍有异常,需要调试 由于没有太多时间再去调试,本人在此倒希望各位大虾调试通过后通知我一声 :) 如果有人帮忙条通,我下次继续上传 :)
java swing 多选下拉框 支持动态加载数据 (优化了网上的下拉框代码)
private JEditorPane content = new JEditorPane(); private JScrollPane scroll = new JScrollPane(content); private JFileChooser filechooser = new JFileChooser() ; private BorderLayout bord = new ...
Java网络编程(第三版)中文版(不看后悔) JAVA Network Programming,Third Edition 原出版社: O'Reilly 作者: (美)Elliotte Rusty Harold [作译者介绍] 译者: 朱涛江[同译者作品] 林剑 丛书名: O'...
Java网络编程(第三版)中文版(不看后悔) JAVA Network Programming,Third Edition 原出版社: O'Reilly 作者: (美)Elliotte Rusty Harold [作译者介绍] 译者: 朱涛江[同译者作品] 林剑 丛书名: O'...
Java网络编程(第三版)中文版(不看后悔) JAVA Network Programming,Third Edition 原出版社: O'Reilly 作者: (美)Elliotte Rusty Harold [作译者介绍] 译者: 朱涛江[同译者作品] 林剑 丛书名: O'...