1

When adding a MouseListener to a JToolBar,

jToolbar.addMouseListener(new MouseInputAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
        log.debug(e.getPoint());
    }
});

The event only fires when clicked outside the JToolBar's gripper.

If I override BasicToolBarUI's createDockingListener():

@Override
protected MouseInputListener createDockingListener() {
    return new MouseInputAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            log.debug(e.getPoint());
        }
    }
}

The event will fire when clicked on the gripper.

So my question is, why? Is the MouseEvent consumed in the dockingListener? But I don't see any code that consumes the event.

1
  • It's likely being consumed automatically by the event processing queue Commented Sep 19, 2013 at 4:15

1 Answer 1

3

The MouseEvent is being automatically consumed by the Container at a number of points for a number of different reasons (some relating to how the native peer needs to deal with the event)...

Most notably in the private method Container#processMouseEvent, but it could be consumed before then

This basically means, when you attach a MouseListener to any component, it will consume all mouse events going to any component (or part thereof) that it resides above.

Think of mouse events like rain. When a raindrop hits something, it stops.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.