Fading ContentPane

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

Fading ContentPane

Postby danthonywalker » Sun Dec 07, 2014 9:50 pm

Hello! For one I am loving your library and the overall aesthetic of the look and feel. Brings a nice modern style to the old Java Swing interface along with some nice utilities.

I am curious however how you went about creating a fading transition content pane for your demo. I tried applying a transition component to the content pane, but whenever I try to play the transition I get an error saying something about how the width and length can't be less than or equal to 0. I've tried setting some minimum size values to the components I'm trying to transition, but nothing seems to work.

Digging around your source code I can't seem to find exactly how you do a fade transition at the start of your demo. Some insight and help would be much appreciated.
Posts: 1
Joined: Fri Nov 28, 2014 11:26 am

Re: Fading ContentPane

Postby mgarin » Mon Dec 29, 2014 2:03 am

First of all - sorry for a very long delay with an answer, was totally busy last four weeks of this year so I weren't able to answer questions in time.

Now to your question - transition setup might be indeed confusing as it requires some actions, though it is demonstrated in code of few examples on the transitions tab.

Here is a separate example displaying how you could transform an image into Swing form (it is actualy the same as Swing component to component transition):
Code: Select all
public class TransitionExample
    public static void main ( final String[] args )
        WebLookAndFeel.install ();

        // First frame content
        final WebImage image = new WebImage ( WebLookAndFeel.getIcon ( 256 ) );

        // Second frame content
        final WebPanel panel = new WebPanel ( new FormLayout ( false, true, 5, 5 ) );
        panel.setMargin ( 10 );
        panel.add ( new WebLabel ( "Login:", WebLabel.TRAILING ) );
        panel.add ( new WebTextField ( "admin" ) );
        panel.add ( new WebLabel ( "Password:", WebLabel.TRAILING ) );
        panel.add ( new WebPasswordField ( "admin" ) );
        panel.add ( new WebLabel ( "Name:", WebLabel.TRAILING ) );
        panel.add ( new WebTextField ( "Mikle" ) );
        panel.add ( new WebLabel ( "Surname:", WebLabel.TRAILING ) );
        panel.add ( new WebTextField ( "Garin" ) );

        // Transition panel and frame
        // final CurtainTransitionEffect effect = new CurtainTransitionEffect ();
        // final SlideTransitionEffect effect = new SlideTransitionEffect ();
        final CurtainTransitionEffect effect = new CurtainTransitionEffect ();
        effect.setSize ( 30 );
        effect.setSpeed ( 1 );
        effect.setSlideDirection ( CurtainSlideDirection.right );
        effect.setType ( CurtainType.fade );
        final ComponentTransition transition = new ComponentTransition ( image, effect );
        TestFrame.show ( transition );

        // Transition action
        WebTimer.delay ( 2000, new ActionListener ()
            public void actionPerformed ( final ActionEvent e )
                transition.performTransition ( panel );
        } );

Basically, the steps are:
1. Create first Swing component (might be a container with other components)
2. Add it into the ComponentTransition (which is basically a simple Swing 1-cell container)
3. When "the time comes" (when you want to switch view) create another component or contaner
4. Call "transition.performTransition ( otherComponent );" to switch view using animated transition

Effect used by transition can be passed into ComponentTransition constructor or changed in runtime. Though it is not recommended to change it while transition is in process as it might cause some visual glitches.
User avatar
Site Admin
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest