O'Reilly logo

Java™ Drawing with Apache Batik: A Tutorial by Alexander Kolesnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying an SVG File

JSVGCanvas can be used to display an SVG document from a file. Let’s see how this can be done.

For this purpose you need to create another simple Swing application. Its code is given in Listing 3.4. Again, it mainly consists of Swing components. You use a JSVGCanvas instance to display an SVG document, a JFileChooser to choose which document to display, and a JButton to invoke the File Chooser. Notice that, unlike in the previous versions of the application, here the canvas size is fixed.

Listing 3.4. The source code of our SVG File Viewer
package com.brainysoftware.batik; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required