我正在用 javafx 11 构建一个项目, 我使用了一个 html 编辑器,我已经成功地自定义了默认的 html 编辑器 但是我不知道如何让拼写检查器在 webview 中工作,我在 html 中设置了拼写检查 =“true”,如下所示
<html dir="ltr">
<head>
<style type='text/css'>
body {
color: #555555;
border: none;
padding: 5VW;
max-width: 90VW;
}
</style>
</head>
<body id="editable" spellcheck="true" contenteditable="true">
</body>
</html>
但是,当我将此 html 页面加载到 webview 时,它不会在单词拼写错误的单词下划线
下面是我的实际java类代码:
公共类 NoteBoard 扩展 VBox { HTMLEditor board = new HTMLEditor();
NoteBoard(){
getChildren().add(board);
board.setMaxWidth(1499);
board.setMinWidth(1498);
setMaxWidth(1500);
setMaxHeight(1000);
setStyle("-fx-background-color:white");
WebView webView = (WebView) board.lookup("WebView");
GridPane.setHgrow(webView, Priority.ALWAYS);
GridPane.setVgrow(webView, Priority.ALWAYS);
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setReadTimeout(30000);
defaultClient.setWriteTimeout(30000);
defaultClient.setConnectTimeout(30000);
// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("d5eea16e-cf1d-47c4-bc92-be06e1acf8a0");
defaultClient.setReadTimeout(30000);
defaultClient.setWriteTimeout(30000);
defaultClient.setConnectTimeout(30000);
WebEngine engine = webView.getEngine();
engine.load("file:/src/main/java/Main/Notes/note.html");
this.setOnKeyPressed(e->{
if(e.isControlDown() && (e.getCode() == KeyCode.S)){
try {
File myObj = new File("note.html");
if (myObj.createNewFile()) {
System.out.println("File created: " + myObj.getName());
FileWriter myWriter = new FileWriter("note.html");
myWriter.write(board.getHtmlText());
myWriter.close();
System.out.println("Successfully wrote to the file.");
} else {
System.out.println("File already exists.");
FileWriter myWriter = new FileWriter("note.html");
myWriter.write(board.getHtmlText());
myWriter.close();
System.out.println("Successfully wrote to the file.");
File file = new File("result.pdf");
ConvertDocumentApi apiInstance = new ConvertDocumentApi();
Boolean includeBackgroundGraphics = true; // Boolean | Optional: Set to true to include background graphics in the PDF, or false to not include. Default is true.
Integer scaleFactor = 56; // Integer | Optional: Set to 100 to scale at 100%, set to 50% to scale down to 50% scale, set to 200% to scale up to 200% scale, etc. Default is 100%. Maximum is 1000%.
try {
byte[] result = apiInstance.convertDocumentHtmlToPdf(myObj);
System.out.println(result);
OutputStream
os
= new FileOutputStream(file);
// Starts writing the bytes in it
os.write(result);
System.out.println("Successfully"
+ " byte inserted");
// Close the file
os.close();
} catch (ApiException e2) {
System.err.println("Exception when calling ConvertDocumentApi#convertDocumentHtmlToPdf");
e2.printStackTrace();
}
System.out.println("done!!!");
}
} catch (IOException e2) {
System.out.println("An error occurred.");
e2.printStackTrace();
}
}
});
}
}