2

I tried the demo of the swingx framework (http://swingx.java.net/). When you close the main window you have a great fading effect. I tried to reach this effect with the JXFrame but it has just the normal closing effect.

Anyone has an idea?

Anthea
  • 3,741
  • 5
  • 40
  • 64

1 Answers1

1

thanks :-)

It's not related to JXFrame (could be done with any Window), just a timeline bound to the window's opacity property. This timeline is started when the application window is closed, the relevant code is in DemoUtils

public static void fadeOutAndDispose(final Window window,
        int fadeOutDuration) {
    fadeOutAndEnd(window, fadeOutDuration, false);
}

public static void fadeOutAndExit(Window window, int fadeOutDuration) {
    fadeOutAndEnd(window, fadeOutDuration, true);
}

private static void fadeOutAndEnd(final Window window, int fadeOutDuration, 
        final boolean exit) {
    Timeline dispose = new Timeline(new WindowFader(window));
    dispose.addPropertyToInterpolate("opacity", 1.0f,
            0.0f);
    dispose.addCallback(new UIThreadTimelineCallbackAdapter() {
        @Override
        public void onTimelineStateChanged(TimelineState oldState,
                TimelineState newState, float durationFraction,
                float timelinePosition) {
            if (newState == TimelineState.DONE) {
                if (exit) {
                    Runtime.getRuntime().exit(0);
                } else {
                    window.dispose();
                }
            }
        }
    });
    dispose.setDuration(fadeOutDuration);
    dispose.play();
}

public static class WindowFader {
    private Window window;

    public WindowFader(Window window) {
        this.window = window;
    }

    public void setOpacity(float opacity) {
        AWTUtilitiesWrapper.setWindowOpacity(window, opacity);
    }
}

Note that the fading effect will no longer work for all frames in jdk7, as the behaviour was changed to effect only undecorated windows

Edit

Timeline (and the callbackAdapter) are classes in Trident, one of Kirill's projects, unfortunately abandoned by him, taken over as Insubstantial (don't have a reference handy, sorry) - but you can take any other or handcode a Timer

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • thank you, I tried to implement that in my code but missed some classes like Timeline and UIThreadTImelineCallbackAdapter ... Is there maybe a library that I miss? – Anthea Nov 23 '11 at 16:40