0

I seem to have a problem working with batikSVG for manupilating SVG using Java. I can display the SVG just fine on the JSVG Canvas but when I try to the canvas's SVGDocument using getSVGDocument it seems to return null. Why is that, and how can I get the actual document?

jSVGCanvas1.setURI(new File("circle.svg").toURI().toString());

    jSVGCanvas1.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
    SVGDocument doc =   jSVGCanvas1.getSVGDocument();
    if(doc==null)System.out.println("null");

The last line tests where doc is null and it always prints null. Please help!

Bashir Beikzadeh
  • 761
  • 8
  • 15

1 Answers1

1

You'll need to wait for the document to load and that happens asynchronously. Something like this...

   jSVGCanvas1.addSVGDocumentLoaderListener(new SVGDocumentLoaderAdapter() {
        public void documentLoadingCompleted(SVGDocumentLoaderEvent e) {
          SVGDocument doc = jSVGCanvas1.getSVGDocument();
          if(doc==null)System.out.println("null");
        }
    });
Robert Longson
  • 118,664
  • 26
  • 252
  • 242
  • Hi, I have another question if you would be so kind to answer. What if I want to change the attributes outside of the "documentLoadingCompleted" method? For example change the attribute at the press of a button. What then? Simply changing the attributes from the element does not work. – Bashir Beikzadeh Jan 14 '13 at 07:04