Example SVG Salamander?

I play with Java and SVG Salamander, but cannot figure out how to make a simple SVG file in JPanel . Can someone give me a brief example? I tried to follow the free tutorial on the official website, but could not find a simple code to better understand.

So, some code is really appreciated! Thanks!

+6
java svg
source share
2 answers
+3
source share

First you need to somehow create a 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 display your file - usually using the paintComponent () method - you only need to do (with g is an instance of Graphics2D):

 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); 
+6
source share

All Articles