简体   繁体   English

如何在 Java fx 中显示 HTML?

[英]How to showing HTML in Java fx?

I am coding a Windows tchat software in JavaFx.我正在 JavaFx 中编写 Windows 聊天软件。 I want to display HTML text but without showing the tags.我想显示 HTML 文本但不显示标签。 How to do that?怎么做? There are some examples:有一些例子:

1) String received: "<p>Toto tata titi</p>" . 1)收到的字符串: "<p>Toto tata titi</p>"
What I want to display: "Toto tata titi".我要显示的内容:“Toto tatatiti”。

  1. Other example: String received: "<p>Test 1 <br> Test 2</p>" .其他示例:收到的字符串: "<p>Test 1 <br> Test 2</p>"
    What I want to display:我要显示的内容:
    "Test 1 “测试一
    Test 2"测试 2"

Thank you for helping.感谢您的帮助。

JavaFX offers the WebView for this case. JavaFX 为这种情况提供 WebView。 You can simply display any HTML Page with it.您可以使用它简单地显示任何 HTML 页面。

String received = "<p>Toto tata titi</p>"; 
WebView webView = new WebView();

WebEngine is a internal component of WebView which manages to load the data which should be displayed in the WebView. WebEngine 是 WebView 的内部组件,它管理加载应在 WebView 中显示的数据。

WebEngine webEngine = webView.getEngine();
webEngine.loadContent(received , "text/html");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM