How to change the attribute of an SVG image in batik during a program?

I want to change the attribute of an SVG document while the program is running by pressing a button (for example, turn the 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 document to get the element by id and change the attribute of the element when I click this button:

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
         el = doc.getElementById("statusColor");
        el.setAttributeNS(null, "stop-color", "green");

    }

Graphics will not be updated! Please, help!

+1
source share

All Articles