Reputation: 387
I am trying to figure out how to read an HTML file into a JEditorPane
.
I have the following code:
JEditorPane editorPane = new JEditorPane();
URL helpURL = MainFrame.class.getResource("user-manual.html");
Now my problem is that the user-manual.html
file needs to be in the bin folder that holds the MainFrame class otherwise it will not work. Now my problem is my directory has to look like this:
as1/ as1/doc/ as1/doc/user-manual.html as1/doc/system-doc.html as1/doc/images/ as1/src/
How do I go about reading the user-manual.html
file into the URL?
Upvotes: 0
Views: 390
Reputation: 2852
possible reasons -
setContent
method might not have been set to "text/html"Upvotes: 0
Reputation: 40168
How about this?
getClass().getClassLoader().getResource("as1/doc/user-manual.html");
Upvotes: 0
Reputation: 74750
The method Class.getResource
accept also semi-relative adresses, like this:
URL helpURL = MainFrame.class.getResource("/as1/doc/user-manual.html");
Then the path is rooted at the jar-file (or classpath directory) instead of the package directory.
Upvotes: 1
Reputation: 77044
You can either add the items directory to your classpath and continue access it as you are now or inside the directory structure as:
MainFrame.class.getResource("as1/doc/user-manual.html");
Upvotes: 0