How to change attribute of an SVG image in batik w

2019-06-01 05:17发布

问题:

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!

标签: java svg batik