gpt4 book ai didi

java - Web View 不显示 HTML

转载 作者:行者123 更新时间:2023-12-01 23:07:36 24 4
gpt4 key购买 nike

我试图在 JavaFx Pane 上显示一些 HTML,但 HTML 不显示。我可能做错了什么?

HTML:

<style type="text/css">
#Wrrpr {
font-family: "Lucida Grande", Tahoma, Verdana, Arial, sans-serif;
font-size: 11px;
color: #930;
border: 1px dashed #090;
height: 95px;
width: 116px;
}
</style>
</head>

<body>
<div id="Wrrpr">Sample Text</div>
</body>
</html>

Controller 类的摘录:

Pane webView = new Pane();
WebView browser = new WebView();
browser.setMaxWidth(116);
browser.setMaxHeight(95);
WebEngine engine = browser.getEngine();
String urlPage = "/WakiliProject/sampleWebView.html";
engine.load(urlPage);
webView.getChildren().add(browser);

最佳答案

您需要将 html 转换为 URL,然后才能将其传递到 WebEngine。

请在您的 Controller 中添加以下行

URL url = getClass().getResource("/WakiliProject/sampleWebView.html");
engine.load(url.toExternalForm());

关于java - Web View 不显示 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22523927/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com