While I move my gaming mouse inside javax.swing.JFrame , all animated GIFs ( javax.swing.ImageIcon inside javax.swing.JLabel ) stop the animation until the mouse stops moving.
This only happens with a gaming mouse with a driver on macOS (tested it with Rocket-Kone XTD and a Razer gaming mouse on two computers). When I use other mice, everything works fine.
Gaming mice also force
javax.swing.Timer stop calling their
actionPerformed() methods.
I opened this topic here for this problem, but this can be solved using
java.util.TimerTask . (
Edit: Actually, TimerTask also does not fix it, because the JFrame does not redraw until the mouse stops moving.)
But I did not find an alternative for GIF animation. I'm more interested in solving the problem instead of using alternatives, although I would be grateful for a working alternative.
The code:
import java.lang.reflect.InvocationTargetException; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class Mouse { public static void main(String[] args) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { new Mouse(); } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } public Mouse() { JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon(getClass().getResource("waiting.gif"))); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.add(label); } }
Application Launch:

MCVE:
import java.lang.reflect.InvocationTargetException; import java.net.*; import javax.swing.*; public class Mouse { public static void main(String[] args) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { try { new Mouse(); } catch (MalformedURLException ex) { ex.printStackTrace(); } } }); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } public Mouse() throws MalformedURLException { JFrame frame = new JFrame(); JLabel label = new JLabel(new ImageIcon( new URL("https://i.stack.imgur.com/HXCUV.gif"))); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.add(label); } }
java timer swing animated-gif macos
Yakuhzi
source share