Search code examples
codenameone

How do I use glass pane but also allow a user entering data in a specific UI component but disable all others?


I would like to design tutorials in my cn1 app. I can have an instructor painted on the glass pane to direct a user to enter required data in UI components step by step.

Can I have a glass pane and also let the user enter data in a specific UI component on the form but disable all others?


Solution

  • You can add a pointer listener to the parent form and if you want to block an action from propagating you can consume() the event. You can get the component at the X/Y location to decide whether the event should be consumed or allowed to proceed.

    Edit. This should look roughly like this:

    Form parentForm = ...;
    parentForm.addPointerReleasedListener(ev -> {
        Component cmp = parentForm.getComponentAt(ev.getX(), ev.getY());
        if(!allowCmpEvent(cmp)) {
            ev.consume();
        }
    });