2
votes

When you make a SpanButton lead for a Container, it doesn't receive the events. I've tried debugging but haven't managed to understand why it doesn't work. It seems to be a CN1 error, but I may have misunderstood something.

Here's a test case to reproduce the issue:

    Form hi = new Form("Welcome", BoxLayout.y());

    //test case shows that when you make a normal Button lead for a Container, 
    //it works as expected.
    //Doing the same with a SpanButton doesn't work.
    //When you click button it correctly hides the Label. 
    //Clicking spanButton doesn't hide the label.
    //
    //Test also shows a second issue: when adding a Command to a SpanButton, 
    //the Command text is shown in parallel with the SpanButton's text


    //edit Button works normal
    Button button = new Button("Normal Button works");
    Label hide2 = new Label("Now you see me, now you don't2");
    Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
        hide2.setHidden(!hide2.isHidden());
        hi.revalidate();
    });
    button.setCommand(cmd2);
    Label editButtonLabel2 = new Label();
    FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]

    Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
     cont2.setLeadComponent(button); //for a normal button, the lead works correctly
    hi.add(cont2);
    hi.add(hide2);

    //with SpanButton it doesn't work:
    SpanButton spanButton = new SpanButton("SpanButton does not work");
    Label hide = new Label("Now you see me, now you don't");
    Command cmd = Command.create("CmdText", null, (ev) -> {
        hide.setHidden(!hide.isHidden());
        hi.revalidate();
    });
    spanButton.setCommand(cmd);
    Label editButtonLabel = new Label();
    FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]

    Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
    cont.setLeadComponent(spanButton); //spanButton made lead for cont, so should receive all events for cont, but doesn't
    hi.add(cont);
    hi.add(hide);


    hi.show();
1

1 Answers

1
votes

Could this be due to SpanButton being a container itself and also having a Lead component which is a Button?

You could create a normal Button and apply that command to it, then set the container's lead component to this Button. You don't have to add this Button to the container, add your SpanButton and the container will still receive all the events.

Form hi = new Form("Welcome", BoxLayout.y());

/*test case shows that when you make a normal Button lead for a Container, 
it works as expected.
Doing the same with a SpanButton doesn't work.
When you click the button, it correctly hides the Label. 
Clicking spanButton doesn't hide the label.

Test also shows a second issue: when adding a Command to a SpanButton, 
the Command text is shown in parallel with the SpanButton's text*/


//edit Button works normal
Button button = new Button("Normal Button works");
Label hide2 = new Label("Now you see me, now you don't2");
Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
    hide2.setHidden(!hide2.isHidden());
    hi.revalidate();
});
button.setCommand(cmd2);
Label editButtonLabel2 = new Label();
FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]

Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
cont2.setLeadComponent(button); //for a normal button, the lead works correctly
hi.add(cont2);
hi.add(hide2);

//with SpanButton it doesn't work:
SpanButton spanButton = new SpanButton("SpanButton does not work");
Label hide = new Label("Now you see me, now you don't");
Command cmd = Command.create("CmdText", null, (ev) -> {
    hide.setHidden(!hide.isHidden());
    hi.revalidate();
});
Button btnHidden = new Button(cmd);

Label editButtonLabel = new Label();
FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]

Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
cont.setLeadComponent(btnHidden); //spanButton made lead for cont, so should receive all events for cont, but doesn't
hi.add(cont);
hi.add(hide);


hi.show();