WebView Follow
Answered
Hi!
Im playing around with WebView.... i want to deploy a plugin including a complete "website" in it. i dont want to load a external website or a local webserver for it.
when i try to load local resources i fail. only my standalone test is working, but the path to my sources is changing if i load the sandbox or the final plugin.
Here is what i try:
public static void standAloneTest() {
String path = System.getProperty("user.dir");
path.replace("\\\\", "/");
path += "/html/index.html";
File f = new File(path);
System.out.println(f);
System.out.println(f.isFile());
try {
String url = f.toURI().toURL().toString();
JFrame jFrame = new JFrame();
jFrame.setVisible(true);
JFXPanel jfxPanel = new JFXPanel();
jFrame.add(jfxPanel);
Platform.runLater(() -> {
WebView webView = new WebView();
jfxPanel.setScene(new Scene(webView));
// webView.getEngine().load("http://www.stackoverflow.com/");
webView.getEngine().load(url);
// webView.getEngine().load("file:///" + url);
});
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
Please sign in to leave a comment.
Michael,
If I understood your correctly your problem is not WebView itself, but the way you construct your URL. When your code is run as a plugin,"user.home" must be pointing to /path/to/IDEA/bin (depending on the platform). It's not where your html resides.
I guess you should do something like this. Say, your project structure is as follows:
- MyProject
- - src
- - - <package>
- - - - Main.java
- - - html
- - - - index.html
When it's compiled into jar, you'll have your "html" at the jar's root. Then, you access it as follows:
This way it should work in either mode. Is that what you're looking for?
Perfect! Thank you!!