Lemur Button AddCommands disappear with new background?

Hi,

im playing with Lemur to see how it works.

I have a Button and added a command. That command is changing the background of the button. When the background of the button has changed I can not access the command. Without the change of the background all commands are working.
Can anyone give me a hint why?
And if it is possible to change the button background from command ?
PS: I found this post
https://hub.jmonkeyengine.org/t/dynamic-background-images-on-lemur-buttons/40314
but it is more about background pictures and lemur styles.

Here are the few lines of code I am using

 QuadBackgroundComponent q1 = new QuadBackgroundComponent(txtele); 
 QuadBackgroundComponent q2 = new QuadBackgroundComponent(txtele2);
...
b2.setName("Status01");
b2.setBackground(q1);
 Command Order_01 = new Command() {
            @Override
            public void execute(Object source) {
                if (b2.getName().equals("Status01")) {
                    //              b2.setBackground(q2);
                    b2.setName("Status02");
                    System.out.println("Order 01 - A");
                } else {
                    //                 b2.setBackground(q1);
                    b2.setName("Status01");
                    System.out.println("Order 01 - B");
                }
            }
        };

        b2.addCommands(Button.ButtonAction.Up, Order_01);

After rereading the post https://hub.jmonkeyengine.org/t/dynamic-background-images-on-lemur-buttons/40314/8 I just tried with the following adjustment, that solved the problem in my little test case.

So cloning did the magic.

 Command Order_01 = new Command() {
            @Override
            public void execute(Object source) {
                if (b2.getName().equals("Status01")) {
                    b2.setBackground(q2.clone());                      
                    b2.setName("Status02");
                    System.out.println("Order 01 - A");
                } else {
                    b2.setBackground(q1.clone());
                    b2.setName("Status01");
                    System.out.println("Order 01 - B");
                }
            }
        };

@pspeed + @zarch thanks for hinting to a solution (I still dont understand it, but it seems to work)

I don’t know specifically why in this case but it is caused by the same “thing” being shared between multiple controls. You then end up with strange behaviour since state starts bleeding between controls.

Glad you fixed it :slight_smile: