views:

26

answers:

1

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?

A: 

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);
}
Maurice Perry
This sort of does what I want, but I'm trying to build a rough scripting language I can use to make the elements on the jEditPane more like javascript. So I can have a Add button and a form slide down and when they click save on the form it adds the record to the page. Just changing the style of link won't accomplish all that. I need to know how to access specific elements and use PutProperty.
Matthew Dunham