I am using a JavaFX WebView to display HTML help:
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import java.net.URL;
public final class HelpPane extends BorderPane {
private static final String HELP_RESOURCE_NAME = "/help/main.html";
public HelpPane() {
WebView webView = new WebView();
WebEngine webEngine = webView.getEngine();
URL url = HelpPane.class.getResource(HELP_RESOURCE_NAME);
webEngine.load(url.toExternalForm());
setCenter(webView);
}
}
The main.html, a style.css and various images all reside in a help folder inside resources :
From main.html, I am using relative links to load CSS and images:
<html>
<head>
<meta charset="utf-8"/>
<link rel="stylesheet" href="style.css"/>
</head>
<body>
<h1>Help</h1>
<img src="img/main-vs-side-panels.png" width="600px"/>
</body>
</html>
Everything works perfectly fine on OSX (both, when launching from IDE and from a jar). On Windows, when launching from jar, the CSS and img links are no longer resolved (launching from IDE works fine).
Is there a better aka more robust way for linking to resources?
