fade In Dialog - Java Swing

Java examples for Swing:JDialog

Description

fade In Dialog

Demo Code


//package com.java2s;

import java.awt.Dialog;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;

public class Main {
    public static void fadeIn(final Dialog win) {
        if (!win.isUndecorated()) {
            return;
        }//  w  ww  .ja v a  2  s .  c o m
        final Timer timer = new Timer(30, null);
        timer.setRepeats(true);
        timer.addActionListener(new ActionListener() {
            private float opacity = 0;

            @Override
            public void actionPerformed(ActionEvent e) {
                opacity += 0.05f;
                win.setOpacity(Math.min(opacity, 1f));
                if (opacity >= 1) {
                    timer.stop();
                }
            }
        });
        win.setOpacity(0);
        timer.start();
        win.setVisible(true);
    }
}

Related Tutorials