I have a fairly simple JavaFX application. It has one window, split in two. On the left is a tableview that lists rows from a database. When you select one of the rows, it displays the XML (also from the database) in a webview on the right. So far so good. I can't for the life of me get any sort of JavaScipt working. My ultimate goal is to get a search and highlight working (as in this great post. Based on my problems there, I thought I'd try and simplify matters by just plugging in a simple JavaScript function to the HTML.
I'm using FXML, if that's relevant. I have a button that for it's OnAction property, calls this method:
@FXML
private void searchBrowser() {
if (webEngine.getDocument() != null) {
highlight(searchField.getText());
}
}
@FXML
private void highlight(String text) {
webEngine.executeScript("test()");
It doesn't throw any errors, and both methods are called in order. Just nothing else happens. The test() function is in the HTML, just a simple alert. If I just save the HTML and load it in Chrome or IE, the function works fine. What am I doing wrong?
First of all I can't find easy way to fix old version for
webView.getEngine().loadContent();
.But i decided to push the same feature on my project. My requirements where syntactic highlight and selected text highlight, so here is what i came up with: (Code is not really optimised, just works and demonstrates how it can be done)
It is huge code for 1 post ,so i will just explain essential parts and post demo git link. Java git path., Resources git path
template HTML
file as a string and fix css and js links, because i store them locally and have no idea how to setup relative path in htmlhtml encoded XML
in template HTML