Search code examples
labelcodenameoneopacityforeground

codename one animate forground of label


This does not work for me. I am attempting to change the color when I press the button.

 Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
    Button button = new Button("button");

    Label l = new Label(" ");
    l.setUIID("DestinationUIID");
    l.getAllStyles().setFgColor(0xff0000);

    Label l$ = new Label("Label");
    l$.setUIID("DestinationUIID");
    l$.getAllStyles().setFgColor(0x00ff00);

    hi.add(l$);

    ComponentAnimation ca = l$.createStyleAnimation("DestinationUIID", 2000);
    l$.getAnimationManager().addAnimation(ca, () -> onCompletion());

    button.addActionListener((e) -> {

        //l$.animate();
        l$.getAllStyles().setFgColor(0xff0000);
         l$.animate();
        //hi.getContentPane().animateHierarchyFade(2000, 0);
    });
    hi.add(button);
    hi.show();

I don't understand the concept of a UIID, or the syntax for animation.


Solution

  • There are lots of ways to animate the foreground from style animation to animate() calls to UITimer.

    Using style animations we can do something like this for a 500ms transition:

    ComponentAnimation ca = myLabel.createStyleAnimation("DestinationUIID", 500);
    myLabel.getAnimationManager().addAnimation(ca, () -> onCompletion());