Posted By:
Heiko_Apel
Posted On:
Thursday, April 25, 2002 07:19 AM
I am trying to read html files from jar-archives and display them in a JEditorPane. I am using the follwowing code, but the pages are not shown in the JEditorPane: JEditorPane HelpPane = new JEditorPane(); HTMLEditorKit htmlKit = new HTMLEditorKit(); HelpPane.setEditorKit(htmlKit); HelpPane.setContentType("text/html"); try { JarFile jar = new JarFile("e:/java/phytophthora/lateblight/classes/PhytMod.jar"); JarEntry jarE = new JarEntry(jar.getEntry("lateblight/docs/help.html")); if (jarE != null) { BufferedReader bf = new BufferedReader(new InputStreamReader(jar.getInputStream(jarE))); long size = jarE.getSize(); int chars_read =
More>>
I am trying to read html files from jar-archives and display them in a JEditorPane.
I am using the follwowing code, but the pages are not shown in the JEditorPane:
JEditorPane HelpPane = new JEditorPane();
HTMLEditorKit htmlKit = new HTMLEditorKit();
HelpPane.setEditorKit(htmlKit);
HelpPane.setContentType("text/html");
try {
JarFile jar = new JarFile("e:/java/phytophthora/lateblight/classes/PhytMod.jar");
JarEntry jarE = new JarEntry(jar.getEntry("lateblight/docs/help.html"));
if (jarE != null) {
BufferedReader bf = new BufferedReader(new InputStreamReader(jar.getInputStream(jarE)));
long size = jarE.getSize();
int chars_read = 0;
char[] chars = new char[(int) size];
while(bf.ready()) {
chars_read += bf.read(chars, chars_read, (int)size - chars_read);
}
bf.close();
text = new String(chars);
HelpPane.setText(text); //or HelpPane = new JEditorPane("text/html", text); also doesn't work
}
}
catch (IOException ex) {
//exception handling...
}
If I extract the files manually and use HelpPane.setPage(URL) instead, it works perfectly. Also
What's wrong???
<<Less