How do I display a String as an HTTP hyperlink in a dialog box?

Sandip Chitale

AWT does not support this directly. There are third party tools which can do that though e.g. ICEBrowser and older awt based HotJava bean.

You should be able to create a subclass of java.awt.Canvas and then simulate the behavior of a Hyperlink yourself. Draw the link text and then an underline using the Graphics.drawString(...) and Graphics.drawLine(...) methods.

Also register a MouseListener to detect clicks over the hyperlink. Also register MouseMotionListener to track the mouse to show 'mouse-over-hyperlink' feedback.

The Swing package has a class called javax.swing.JEditorPane which support rendering of HTML when its contentType is set to "text/html". Then you can show arbitrary HTML including hyperlinks.
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact