Java tutorial
//package com.java2s; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JDialog; import javax.swing.Timer; public class Main { /** * Creates an animation to fade the dialog opacity from 1 to 0. */ public static void fadeOut(final JDialog dialog) { final Timer timer = new Timer(10, null); timer.setRepeats(true); timer.addActionListener(new ActionListener() { private float opacity = 1; @Override public void actionPerformed(ActionEvent e) { opacity -= 0.15f; dialog.setOpacity(Math.max(opacity, 0)); if (opacity <= 0) { timer.stop(); dialog.dispose(); } } }); dialog.setOpacity(1); timer.start(); } }