java 如何在java应用程序的文本区域显示html格式的文本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2441584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:09:49  来源:igfitidea点击:

How to display html formatted text in text area of java application?

javaswingweb-scraping

提问by Deepak Yadav

I am scrapping data from web site using my java application and want to display the result after parsing code of html page in a Text Area made in Swing.

我正在使用我的 java 应用程序从网站上抓取数据,并希望在解析 Swing 中制作的文本区域中的 html 页面代码后显示结果。

Text like: hello <b>every</b>oneshould be displayed as: 'hello everyone' in text area. Thanks!!

文本如:hello <b>every</b>one应在文本区域显示为:'hello everyone'。谢谢!!

采纳答案by camickr

You can use a JEditorPane to display HTML or a JTextPane, which allows you to set attributes for specific characters. Read the API and you will find a link to the Swing tutorial which provides examples.

您可以使用 JEditorPane 来显示 HTML 或 JTextPane,它允许您为特定字符设置属性。阅读 API,您将找到指向提供示例的 Swing 教程的链接。

回答by Omar Jaber

JEditorPane ep = new JEditorPane();
ep.setContentType("text/html");
ep.setText("html code");

回答by Artic

There is no way to see formated text inside of textarea( text in name of tag mean text not html). If you don't need to submit code inside area - you can use some style magic for div element. If you need to submit - use some WYSIWYG editor. There is free one FCK

无法看到 textarea 内的格式化文本(标签名称中的文本表示文本不是 html)。如果您不需要在区域内提交代码 - 您可以对 div 元素使用一些样式魔术。如果您需要提交 - 使用一些 WYSIWYG 编辑器。有一个免费的 FCK