开发者

How do I modify an html link attribute when the html is loaded into a jEditPane? JDK6

I understand how to get the attribute with:

public void hyperlink开发者_如何学运维Update(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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜