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!

1 Answer 1

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");
        }
    });
1
  • 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. Jan 14, 2013 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.