在WebView.replaceContent中加载本地CSS文件

时间:2014-02-23 22:13:27

标签: java javascript webview javafx

我正在尝试使用

在JavaFx中实现代码编辑器

https://gist.github.com/jewelsea/1463485

但问题是它从互联网下载CSS / Javascript以加载CodeMirror。有没有办法下载这些文件并将它们放在Netbeans本地加载它们?我对Java很有经验,但不是JavaFX或HTML。

1 个答案:

答案 0 :(得分:0)

请将CSS / Javascript放在类路径中并使用以下代码:

private final String editingTemplate =
"<!doctype html>" +
"<html>" +
"<head>" +
" <link rel=\"stylesheet\" href=\"codemirror.css\">" +
" <script src=\"codemirror.js\"></script>" +
" <script src=\"clike.js\"></script>" +
"</head>" +
"<body>" +
"<form><textarea id=\"code\" name=\"code\">\n" +
"${code}" +
"</textarea></form>" +
"<script>" +
" var editor = CodeMirror.fromTextArea(document.getElementById(\"code\"), {" +
" lineNumbers: true," +
" matchBrackets: true," +
" mode: \"text/x-java\"" +
" });" +
"</script>" +
"</body>" +
"</html>";

我只是想从类路径而不是互联网中选择CSS / Javascript