gumuruh
gumuruh

Reputation: 2570

Java Swing / AWT with setIcon Gif Animated High Load

I Have 1 single java app. ONly Containing 1 JMenu with 48 JMenuItem(s). Each JMenuItems i set the Icon with Animated GIF.

I have no problem creating it. And I also have no problem when Running it. But the problem came, when I running it, and then viewing the JMenuItem. My GIF(s) Animation seems consuming the PC Process very high! And the ANimation seems jumping too fast! It's not the usual animation framerate, tough.

So anytime when I run the java app, and then trying the JMenuItem, The CPU Process is getting higher...!

Look at this Preview: It's taken when My java app runs. What's the best way to solve this?

Upvotes: 0

Views: 1052

Answers (2)

gumuruh
gumuruh

Reputation: 2570

I have found the solutions guys! The GIF Animation has lots of frames. In each frames they have their own timing. When I reopened one single GIF Animation File, I could see clearly that the 0-time framerate is the problem. Now I should Changed it to somewhat above 0.1 framerate, that's all problem solved.

Upvotes: 1

Andrew Thompson
Andrew Thompson

Reputation: 168825

What result do you get from this SSCCE? My system peaks to 40 at start-up then jumps to an average of around 20-30. The rendering of the animated GIFs is somewhat jerky.

import java.awt.*;
import javax.swing.*;

class Gif48 {

    public static void main(String[] args)  {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                String url = "http://1point1c.org/gif/thum/plnttm.gif";
                int w = 12;
                int h = 4;
                JPanel p = new JPanel(new GridLayout(h,w,2,2));
                String pre = "<html><body><img src='";
                String post = "'>";
                for (int ii=0; ii<w*h; ii++) {
                    JLabel l = new JLabel(
                        pre + url + post );
                    l.setBackground(Color.BLACK);
                    l.setOpaque(true);
                    p.add(l);
                }
                JOptionPane.showMessageDialog(null, p);
            }
        });
    }
}

What's the best way to solve this?

Don't use animated GIFs in the controls of GUIs.

Upvotes: 3

Related Questions