I understand how to get the attribute with:
public void hyperlinkUpdate(HyperlinkEvent e) {
e.getSourceElement().getAttributes().getAttribute(HTML.Attribute.COLOR);
How do I change that attribute?
I understand how to get the attribute with:
public void hyperlinkUpdate(HyperlinkEvent e) {
e.getSourceElement().getAttributes().getAttribute(HTML.Attribute.COLOR);
How do I change that attribute?
This code changes the style of the element. Hope it will help...
private void editorHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
changeStyle(evt.getSourceElement(), "a:hover");
} else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
changeStyle(evt.getSourceElement(), "a");
}
}
private void changeStyle(Element el, String styleName) {
HTMLDocument doc = (HTMLDocument)editor.getDocument();
StyleContext ss = doc.getStyleSheet();
Style style = ss.getStyle(styleName);
int start = el.getStartOffset();
int end = el.getEndOffset();
doc.setCharacterAttributes(start, end - start, style, false);
}