| |
14. 35. 7. How to change mouse cursor during mouse-over action on hyperlinks |
|
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLFrameHyperlinkEvent;
public class Main implements HyperlinkListener {
private JEditorPane pane;
public Main(JEditorPane jep) {
pane = jep;
}
public void hyperlinkUpdate(HyperlinkEvent he) {
HyperlinkEvent.EventType type = he.getEventType();
if (type == HyperlinkEvent.EventType.ENTERED) {
System.out.println(he.getURL().toString());
} else if (type == HyperlinkEvent.EventType.EXITED) {
System.out.println("exit");
} else if (type == HyperlinkEvent.EventType.ACTIVATED) {
if (he instanceof HTMLFrameHyperlinkEvent) {
HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) he;
HTMLDocument doc = (HTMLDocument) pane.getDocument();
doc.processHTMLFrameHyperlinkEvent(evt);
} else {
try {
pane.setPage(he.getURL());
System.out.println(he.getURL().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
|
|
|