Hi all,
in top section of my chat window, where messages come in, I have a JTextPane… is it possible to do a HyperlinkListener in a JTextPane? I hear it has to be a JTextEditor, that you have to use HTMLEditorKit, is this right? I would have to start from scratch, since am using JTextPane and use styles for the different font colors… for example:
doc = textAreaTop.getStyledDocument();
…
StyleConstants.setForeground(msgBody, fontColorMyMsg);
msgBodyIn = textAreaTop.addStyle(“d”, null);
…
doc.insertString(doc.getLength(), iMsgS, msgBody);
etc…
I have this code for HyperlinkListener, which compiles fine, but does not do the trick:
URL url;
public void hyperlinkUpdate(HyperlinkEvent he) {
if (he.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
url = he.getURL();
System.out.println(url.toString()); // prints url ok…
if (he.getEventType() == HyperlinkEvent.EventType.ENTERED) {textAreaTop.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
if (he.getEventType() == HyperlinkEvent.EventType.EXITED){
textAreaTop.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
getAppletContext().showDocument(url, “_blank”);
}
}
I would very much appreciate some help here, as to how to implement HyperlinkListener in JTextPane (if this is at all possible…) I know this is not strictly a Smack question, but I figured this would still be a good place to ask since, well, plenty of folks here must be doing HyperlinkListeners… thank you very much…