[英]JavaFX WebView doesn't render JSF page correctly (symbols instead of values from beans)
[英]JavaFX WebView doesn't Render CSS/HTML Text Correctly
如標題所示,我試圖編寫將在WebView
對象中呈現的CSS / HTML,但是正在編寫的HTML不能正確呈現。
這是我用於測試的示例文本:
<style>
.rainbow {
background-image: -webkit-gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
background-image: gradient( linear, left top, right top, color-stop(0, #f22), color-stop(0.15, #f2f), color-stop(0.3, #22f), color-stop(0.45, #2ff), color-stop(0.6, #2f2),color-stop(0.75, #2f2), color-stop(0.9, #ff2), color-stop(1, #f22) );
color:transparent;
-webkit-background-clip: text;
background-clip: text;
}
</style>
<table border=1>
<tr><th>Header 1</th><th>Header 2</th></tr>
<tr><td>Entry 1-1</td><td>Entry 1-2</td></tr>
<tr><td>Entry 2-1</td><td>Entry 2-2</td></tr>
</table>
<p>This is a personal manifesto that I'm going to write here and hope that noone sees it because I'm really not certain that anyone is going to be happy if they see it. Prepare yourself, because this is going to be super controversial and politicial.</p>
*Deep breath*
<h1><span class="rainbow">Big Bang Theory Sucks!</span></h1>
如果我只是將其加載到一個簡單的文本文檔.html
,並通過Web瀏覽器加載它,那么它將正常工作:
但是,以下簡單的JavaFX代碼會錯誤地呈現html:
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebView;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
BorderPane root = FXMLLoader.load(getClass().getResource("/application/WebViewAndTextInput.fxml"));
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
TextArea textArea = (TextArea) root.getLeft();
WebView webView = (WebView) root.getRight();
webView.getEngine().loadContent(textArea.getText());
textArea.textProperty().addListener((e) -> {
webView.getEngine().loadContent(textArea.getText());
});
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.web.WebView?>
<BorderPane prefHeight="450.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.111">
<right>
<WebView prefHeight="-1.0" prefWidth="400.0" />
</right>
<left>
<TextArea prefWidth="300.0" text="<span style="color:#ff0000">Hello World!</span>" wrapText="true">
<font>
<Font name="Courier New" size="14.0" />
</font>
</TextArea>
</left>
</BorderPane>
這顯然是災難性的,因為現在,我的超級有爭議的觀點被錯誤地呈現的文字所審查! 我是否需要更改WebView對象才能正確呈現此文本,或者這是WebView呈現引擎中的錯誤嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.