How should HTML for Java components reference resources? -



How should HTML for Java components reference resources? -

resources html (style sheets, images etc.) might not loaded correctly when:

a swing app. distributed, or when set jar file. the html generated @ run-time.

how can such resources accessed reliably in html?

html jar file links resources (e.g. css or images) relative references work fine.

e.g.

this illustration loads html (that has relative reference image) jar.

import javax.swing.*; import java.net.url; class showhtml { public static void main(string[] args) { final string address = "jar:http://pscode.org/jh/hs/object.jar!/popup_contents.html"; swingutilities.invokelater(new runnable() { public void run() { seek { url url = new url(address); jeditorpane jep = new jeditorpane(url); jframe f = new jframe("show html in jar"); f.setdefaultcloseoperation(jframe.exit_on_close); f.add(new jscrollpane(jep)); f.pack(); f.setsize(400,300); f.setlocationbyplatform(true); f.setvisible(true); } catch(exception e) { e.printstacktrace(); } } }); } } screenshot

html

the html beingness loaded.

class="lang-html prettyprint-override"><!doctype html public "-//w3c//dtd html 3.2//en"> <!-- * copyright (c) 1997 sun microsystems, inc * rights reserved. * notice of copyright on source code * product not indicate publication. * * restricted rights legend: use, duplication, or disclosure * u.s. authorities subject restrictions set forth * in subparagraph (c)(1)(ii) of rights in technical info * , computer software clause @ dfars 252.227-7013 (oct. 1988) * , far 52.227-19 (c) (june 1987). * * sun microsystems, inc., 2550 garcia avenue, * mount view, california 94043. * --> <html> <head> <title> editing project attributes </title> </head> <body bgcolor="#ffffff"> <img src="images/popup_icon.gif" width="24" height="24"> <b>popup window</b> <p> popup windows appear near location activated. not contained in frames , cannot resized or moved user. popups dismissed clicking anywhere in help viewer. <p> popup windows can activated clicking on text object, graphic object, or jcomponent button. 3 examples included in demo. <p> <a href="popup_contents2.html">more...</a> </body> </html> e.g. 2

for dynamically created html, jre probably utilize class file's location presumed location of html. remove doubt, can specify base element in head.

import javax.swing.*; class htmlusingbase { public static void main(string[] args) { final string htmlcontent = "<html>" + "<head>" + "<base href='http://www.gravatar.com/'>" + "</head>" + "<body>" + "<h1>image path base</h1>" + "<img src='avatar/a1ab0af4997654345d7a9" + "49877f8037e?s=128&d=identicon&r=pg'" + " width='128' height='128'>" + "</body>" + "</html>"; swingutilities.invokelater(new runnable() { public void run() { jlabel label = new jlabel(htmlcontent); joptionpane.showmessagedialog(null, label); } }); } } screenshot

java html swing jlabel jeditorpane

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -