Command on mouse button release with Lemur

I’m making a menu appear when I press a mouse button on something on the scene (using the jme3 default inputManager) and disappear when I release it. The thing is that the menu is a custom lemur container with some buttons. The problem comes when I try to make that buttons fire based on the mouse location when releasing.

The gui can’t know anything about the scene so I can’t make a boolean trick to make it work.

I tried with:

button.addCommands(Button.ButtonAction.Up, new Command<Button>() { ... });

but, obviously, for that first I need the button to be pressed (but there is no way to make it by code or at least I don’t know it. If it were, I could press it on highlight).

Any help is welcome :wink:

The reason the up doesn’t come is because the down doesn’t come (as you’ve discovered) but that’s because the mouse event infrastructure didn’t ‘capture’ the event.

So you coded your own pick infrastructure?

If you uses Lemur’s pick event infrastructure then you at least have some options here. If you register mouse listeners with the various parts then you have some more control over how you handle the events. It’s still a little tricky but it can be done, I think. (For example, if you don’t consume the move events then you will at least get those as you drag around. The mouse release will be delivered to the first component that ‘captured’ it but you can also detect what it’s over at that point.)

Yep :S, but it isn’t incompatible with Lemur’s infrastructure. I forgot it existence and I missed: Modules · jMonkeyEngine-Contributions/Lemur Wiki · GitHub which code I think is a little bit deprecated but it still helping :smiley: .

Thanks for your help, I did it with:

MouseEventControl.addListenersToSpatial(desiredButton, new DefaultMouseListener() {
    public void mouseButtonEvent(MouseButtonEvent evt, Spatial target, Spatial capture) {
        if(evt.isReleased()) {

this isn’t fully true. Is it normal that if I add that listener to the spatial, the com.jme3.input.controls.ActionListener doesn’t receive the event?, even if it is not consumed by Lemur?.

I’m not sure. It might be that Button automatically consumes some of its events that it delivers to commands. You’d have to do a little digging, I guess… because it’s hard for me to test your situation.

Well, it consumes it in the simplest case:

    public void simpleInitApp() {
        // Lemur Gui setup

        Container mainWindow = new Container();
        mainWindow.addChild(new Label("--- Buttons Window ---"));

        Button button = mainWindow.addChild(new Button("Change Material"));

        MouseEventControl.addListenersToSpatial(button, new DefaultMouseListener() {
            public void mouseButtonEvent(MouseButtonEvent event, Spatial target, Spatial capture) {
                System.out.println("Event from lemur: " + event.isReleased());

        mainWindow.setLocalTranslation(300, 300, 0);

        inputManager.addMapping("Click", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addListener(this, "Click");

    public void onAction(String name, boolean isPressed, float tpf) {
        System.out.println("Action: " + name + ", isPressed: " + isPressed);

Where the onAction is being called only if the Lemur’s DefaultMouseListener isn’t.

Override the other DefaultMouseListener methods to do nothing. One of them might be consuming the event.

I’m afraid not, I looked at the code and also implemented MouseListener and the same is happening.

Weird… I don’t think Lemur consumes the events unless you do. Not sure what is happening.

I just found it. What I’m using is a button and the buttons always consume their events (com.simsilica.lemur.Button [243]). I suppose that I should not use a button but create a custom one instead.

Thanks for all.

Yeah, could be. Note: a button is just a label with built in mouse/command handling. So if you are doing your own mouse handling a label is probably better, I guess.