Icon icon = new ImageIcon(getClass().getResource( "/img/icon.gif" ) );
aButton = new JButton("Its a button", icon);
Is there some kind of method that can stop an animated from playing?
I was thinking of assigning a static jpg of the gif, then when I hover, assign the animated gif, but I don't think there is an event for taking off mouse in MouseMotionListener
so I can load back the static jpg.
The gif loops in the button, however, if I hover over it, it disappears.
How can I make the gif static if my mouse cursor is not on the button?
If I use MouseMotionListener
, does it fire an event if I take off my mouse?
@Override
public void mouseMoved(MouseEvent e) {
//play the gif
//if I take mouse off, call some method to stop playing animated gif
}
@Override
public void mouseDragged(MouseEvent e) {
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…