I'm toying with Java and SVG Salamander but can't quite 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.
The repository has example code. If you want to use the latest, there are a few steps involved:
Install Apache Maven.
Clone the repository somewhere:
Update
pom.xml
:Change the
source
,target
, and JDK version numbers:Save
pom.xml
.Generate a JAR file using Maven:
mvn package
Copy
target/svgSalamander-1.1.2.jar
(be sure to change the version number is necessary) to the libraries directory of your program (e.g.,libs
).If your program is using Gradle for building, update the dependencies to use the local JAR file:
If you're using a different build system, you'll have to change the dependencies accordingly. From there, here's a class that uses SVG Salamander to scale and rasterize a vector graphic resource file:
Use the
SvgRasterizer
as follows:That image can be added to a Swing component without much effort. For example, here's a
JComponent
that can be treated much like any other: