DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
doc = (SVGDocument)impl.createDocument(svgNS, "svg", null); svgCanvas.setSVGDocument(doc);
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);Element svgRoot = doc.getDocumentElement();
// set the width and height attribute on the root svg element
svgRoot.setAttributeNS(null, "width", "400");
svgRoot.setAttributeNS(null, "height", "450");
Element rectangle = doc.createElementNS(svgNS, "rect");
rectangle.setAttributeNS(null, "x", "10");
rectangle.setAttributeNS(null, "y", "20");
rectangle.setAttributeNS(null, "width", "100");
rectangle.setAttributeNS(null, "height", "50");
rectangle.setAttributeNS(null, "style", "fill:red");
svgRoot.appendChild(rectangle);((EventTarget)rectangle).addEventListener("click", new EventListener() {
public void handleEvent(org.w3c.dom.events.Event evt) {
Element target = (Element)evt.getTarget();
String style = target.getAttributeNS(null, "style");
if ("fill:red".equals(style)) {
target.setAttributeNS(null, "style", "fill:blue");
} else {
target.setAttributeNS(null, "style", "fill:red");
}
}}, false);
This starts out as a copy of one of the code samples. I inserted the "addEventListener" part.
handleEvent does get called each time I click the rectangle, and the "style" attribute does change, but the displayed color of the rectangle stays red. I've tried calling svgCanvas.paintComponent(svgCanvas.getGraphics( )) after resetting the style, but no effect.
Obviously I'm missing something basic here, or I'm on the wrong track altogether. Any help would be appreciated.
Thanks,
Steven Gollery [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
