Java Glossary : HTML Rendering

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : H words : HTML Rendering.

HTML Rendering
HTML Rendering refers to analying the tags such as <b> and merging them with the text to produce a formatted display.

In Applets

If you writing Java source code for an Applet, you can persuade the browser you are running under to display an HTML page with:

java.net.URL url = new java.net.URL ( "http://mindprod.com" );
getAppletContext().showDocument(url );

That code will fail with a NullPointerException if you attempt it in an application. You can catch all exceptions and just ignore the request in code that sometimes runs as an Applet and sometimes as an application.

There are some catches:

In Applications

Unfortunately that does not allow you to take a hunk of HTML you have in a String, perhaps as the result of a POST, and display it. In that case you somehow have to persuade your server to put that html in a file where you can find it via URL. Alternatively you could use Sun's not-free HTML rendering classes.

In Java 1.2 there is javax.swing.text.HTMLEditorKit. which offers primitive HTML 3.2 rendering ability, inching toward HTML 4 compatibility. You use it like this:

output = new JEditorPane();
output.setContentType( "text/html" );
output.setEditable( false );

From then on text in the pane is rendered as HTML. You can also use

output.setPage( "http://mindprod.com" );

to render a page.

In older JVMs, if you are writing an application you are SOL. For applications, there is no standard HTML rendering class, though BISS-AWT has some primitive HTML rendering code. Andrew Moulden offshore@netcomuk.co.uk has also written Calpane an HTML rendering class, based on Swing.

Spawning A Browser

Even displaying spawning a browser to display a variable URL is quite a production. There is no platform-independent API call to do it. Here is a kludge to pull it off with code that checks the platform.

BrowserLauncher works on Mac and Windows only to launch the default browser from an application. This is useful to implement the help files as HTML.

You can use exec to launch a browser from an application. You can specify the particular browser or use the url form to let Windows decide which browser to use. Just feed a URL string to the Windows command processor.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 2924.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/htmlrendering.html J:\mindprod\jgloss\htmlrendering.html