问题
I want to be able to change the attribute of an SVG document while the program is running by pressing a button (eg turn a black square into blue by changing the fill color). Here is my code:
this.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
@Override
public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
setupSVGDocument();
}});
}
private SVGDocument doc;
private void setupSVGDocument(){
doc = this.getSVGDocument();
}
Then I want to be able to use the doc to get the element by id and change the attribute of an element when pressing a button like this:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
el = doc.getElementById("statusColor");
el.setAttributeNS(null, "stop-color", "green");
}
The graphic won't update! Please help!
来源:https://stackoverflow.com/questions/14314035/how-to-change-attribute-of-an-svg-image-in-batik-while-in-program