Hehe Muha
Hehe Muha

Reputation: 19

SVG Animation with SVG Salamander (Java 1.8)

I'm using SVG Salamander and Java(1.8). How should I animate the SVG image?

The loaded .svg file already contains the animations. I think I need to update somehow the image, but how?

I heard you can animate each DOM element through SVGUniverse. But that sounds kinda ugly...

current hierarchial usage, if it helps: SVGPanel <- Jlabel <- SVGIcon

Upvotes: 0

Views: 1260

Answers (1)

Soley
Soley

Reputation: 1776

I found this answer.

new Timer(100, new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    long diff = System.currentTimeMillis() - start_time;
                    icon.getSvgUniverse().setCurTime(diff % (10 * 1000));
                    try {
                        icon.getSvgUniverse().updateTime();
                    } catch (SVGException ex) {
                        ex.printStackTrace();
                    }
                    icon.paintIcon(null, g2, 0, 0);
                    //or repaint it somehow!
                }
            }).start();

Notice that when your animation is T seconds, (10 secons * 1000 here), you have to animate your file within 0ms-9999ms. hitting 10th seconds will return it to 0-second.

Upvotes: 1

Related Questions