Reputation: 73
how would I load local files relative to the current java file in JWebbrowser?
I know that I could load my page with navigate("path");
the problem is how to set relative path!
for example my java code is in : D:\Eclipse_Project\MyProject\src\javaCode\browser.java and the html file is in : D:\Eclipse_Project\MyProject\src\pages\html.html
but I don't want to use as follow:
webBrowser.navigate("file:///D:/Eclipse_Project/MyProject/src/pages/html.html");
Edit:
my html file also contains CSS an javaScript.
Upvotes: 0
Views: 667
Reputation: 503
If it's still actual, I had the same problem, this is the solution:
you need to use webserver like that:
webBrowser = new JWebBrowser();
webBrowser.navigate(WebServer.getDefaultWebServer().getClassPathResourceURL(getClass().getName(), "your_html_content.html"));
Upvotes: 0
Reputation: 261
Please try the following code:
1. Read html content with scanner.
2. Set html string to webBrowser.
String webContent = new Scanner(new File("src\\pages\\html.html")).useDelimiter("\\Z").next();
webBrowser.setHTMLContent(webContent);
Upvotes: -1