这可能是一个简单的问题,但我似乎无法做到这一点!如何在单击超链接时触发上下文弹出菜单?
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);
}
}
}