How to change attribute of an SVG image in batik while in program?

好久不见. 提交于 2019-12-08 05:59:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!