Use a Hyperlink to Invoke a Dialog in JEditorPane
R. Kevin ColeMarch 03, 2004

I once wrote an HTML custom-tag editor that required that a dialog box pop-up in response to a click on one of the hyperlinks. I developed the following technique to accomplish that task:

The technique can be summarized in the following steps:

  1. Attach a HyperlinkListener to your JEditorPane.

  2. In the hyperlinkUpdate event handler, look for a custom dialog protocol.

  3. Invoke the dialog using a link that looks like this:
    <a href="dialog://something.com">Popup Dialog</a>

Then, in the HyperlinkListener, look for the "dialog" string in the HyperlinkEvent's description like this:

public void hyperlinkUpdate(HyperlinkEvent event) 
{
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
{
/* Process our custom dialog hyperlinks */
if( (event.getDescription() != null)
&& event.getDescription().substring(0,6).equals("dialog") )
{
... popup a dialog ...
}
else
{
/* Process all other hyperlinks */
try
{
htmlPane.setPage(event.getURL());
} catch(IOException ioe)
{
// Some warning to user
}
}
}
}
.
.
.