Recent top five:
Java.next -- Four languages that represent the future of Java
Blogger Stuart Halloway has begun a series of posts on trends that point to the future of the Java platform. In his first
post, he compares Clojure, Groovy, JRuby, and Scala -- four wildly different languages that nonetheless all play together
in the JRE. Find out what unites these languages and what they can tell us about the future of Java-based development ...
| Enterprise AJAX - Transcend the Hype |
| Memory Analysis in Eclipse |
| Oracle Compatibility Developer's Guide |
| Memory Analysis in Eclipse |
JEditorPane class displaying some pretty spiffy HTML documents. JEditorPane doesn't render HTML all by itself, though. It uses a group of classes that make up what Swing refers to as an editor kit. The editor kit attached to a JEditorPane tells the pane how to draw text, images, and components based on a stream of input data -- like an HTML file. It also dictates
how the pane will react to user input. For example, when displaying an HTML document, JEditorPane uses the HTMLEditorKit class.
The HTMLEditorKit class delegates parsing and rendering responsibilities to a group of HTML-aware classes. The event handling is done directly
in HTMLEditorKit itself. The editor kit has a mouse listener, and when mouse clicks occur, HyperlinkEvent objects are generated. This means that not only do images show up, but the hyperlinks actually work! Well, almost.
The HyperlinkEvent class appears to support three subcategories of hyperlink events -- entered, exited, and activated -- so, you should be able
to write a pretty quick listener class that does all the work for you: changing the mouse pointer when it passes over a link
and jumping to a new document when the user clicks on the link. SimpleLinkListener is just such a class. (Of course, this version also has a few extras built in to allow you to track current and future sites,
just as you've come to expect from a real browser.)
With the listener attached to an editor pane, you'll have a minimal browser functioning in less than 30 lines of code. The
TestBrowser class shows a slightly more interesting browser (see below) written with only 75 lines of code. Not bad, eh?

Your new mini-browser showing off hyperlink enter/exit events
If you want to take this app out for a quick test drive, just click on the button below. Of course, you'll need to have Swing installed on your system. See the sidebar, Installing Swing, for step-by-step instructions on the installation process.
One thing to watch out for, though. The HTML 3.2 support in the HTMLEditorKit is not quite perfect yet. While this area is under constant improvement, you may find some HTML pages which throw errors
during formatting. (They throw a javax.swing.text.StateInvariantError to be precise.) It shouldn't stop the page from loading, but you might not see everything exactly where the authors wanted
it go. Most basic HTML pages do not display these errors.
Now, this little app could easily serve as a help system or in-lined browser, but there's a small problem, which you've likely already noticed: although jumping to links works great, the mouse cursor never changes as you move it over links. In addition, the status bar is never updated with the preview URL. In fact, the enter and exit link events aren't generated at all. I'm not really sure why this happens; I suppose it could be an oversight in the design. At any rate, it's frustrating and it needs to be fixed.