You can use Trident to interpolate various properties in your class. Here is a demo that animates panel's background:
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.pushingpixels.trident.Timeline;
import org.pushingpixels.trident.Timeline.RepeatBehavior;
public class TestPanel {
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.add(new JLabel("Some text"));
frame.add(panel);
frame.pack();
frame.setVisible(true);
final Timeline timeline = new Timeline(panel);
timeline.addPropertyToInterpolate("background", panel.getBackground(),
Color.red);
timeline.setDuration(1000);
timeline.playLoop(5, RepeatBehavior.REVERSE);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
EDIT: comments to auto hide a popup
You can use timer to hide a popup, for example:
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TempPopup {
public static void main(String[] args) {
JOptionPane pane = new JOptionPane("Message",
JOptionPane.INFORMATION_MESSAGE);
final JDialog dialog = pane.createDialog(null, "Title");
Timer timer = new Timer(2000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
dialog.dispose();
}
});
timer.setRepeats(false);
timer.start();
dialog.setVisible(true);
dialog.dispose();
}
}