tags:

views:

90

answers:

2

Hi there. I'm toying with Java and SVG Salamander but cant quiet get how to render a simple SVG file into a Jpanel. Could someone give me a brief example? Tried to follow the loose tutorial in the official site, but could not find a simple code to get a better understanding.

So, some code is really appreciated! Thanks!

A: 

Here is some exmple Code

https://svgsalamander.dev.java.net/docs/exampleCode/SVGIODemo.html

Andreas

Andreas
A: 

First, you need to somehow create the diagram (com.kitfox.svg.SVGDiagram).

File f = new File(mysvgfile);
SVGUniverse svgUniverse = new SVGUniverse();
SVGDiagram diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(f.toURL()));

Now, when you want to render your file - typically from the panel's paintComponent() method - you only need to do (with g being the Graphics2D instance):

diagram.render(g);

And (as usual?), if you want to draw it in some modified way:

AffineTransform oldTransform = g.getTransform();
g.scale(...);
g.translate(...);
...
diagram.render(g);
g.setTransform(oldTransform);
Oak