Manipulando cliques com o hiperlink em um JTextPane
Eu estou tentando detectar cliques direito em hiperlinks em um JTextPane no meu programa. Não há realmente nada sobre o assunto online. Alguém pode me ajudar?
public class rchltest extends Applet {
public void init() {
JPanel panel = new JPanel(false);
JEditorPane gentextp = new JTextPane();
JScrollPane scrollPane = new JScrollPane(gentextp);
panel.add(scrollPane);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
gentextp.setContentType("text/html");
gentextp.setEditable(false);
gentextp.addHyperlinkListener(new texthll());
gentextp.setPreferredSize( new Dimension( 500, 400 ) );
gentextp.setText("Here is a <a href='http://A'>hyperlink</a>");
this.add( panel );
}
}
class texthll implements HyperlinkListener {
public void hyperlinkUpdate(HyperlinkEvent event) {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
JEditorPane pane = (JEditorPane)event.getSource();
URL url = event.getURL();
// Show the new page in the editor pane.
JOptionPane.showMessageDialog( null, url);
}
}
}