Possibility to pass mouseevents through visible component on glasspane

Hello!

I don’t know if this is the right place to post my question… I’ll give it a try.

Is there any possibility to ignore or pass (incoming mouseevents on a component which is placed on the glasspane of a jframe? I would be happy with some “pass(MouseEvent e)” method… I found the isConsumed flag. But I don’t know how to use it. By the way I don’t want to / cannot hide the component by setting the visibility to false.

Thanks in advance
Klemens

Hi, you need to redispatch the mouse events to the underlying components…
If I remeber well this method come from the java tutorial…

    private void redispatchMouseEvent(MouseEvent e)
    {
        Point glassPanePoint    = e.getPoint();
        Container container     = frame.getContentPane();
        Point containerPoint    = SwingUtilities.convertPoint(
                this,
                glassPanePoint,
                container);
        
        if (containerPoint.y >= 0)
        {
            Component component =
                    SwingUtilities.getDeepestComponentAt(
                    container,
                    containerPoint.x,
                    containerPoint.y);
            
            // TODO : Remove this, test only
            if( component instanceof JPanel )
            {
                frame.requestFocus();
            }
            // END remove
            
            if ((component != null) )
            {
                Point componentPoint = SwingUtilities.convertPoint(
                        this,
                        glassPanePoint,
                        component);
                
                component.dispatchEvent(new MouseEvent(component,
                        e.getID(),
                        e.getWhen(),
                        e.getModifiers(),
                        componentPoint.x,
                        componentPoint.y,
                        e.getClickCount(),
                        e.isPopupTrigger()));
            }
        }
    }

It may still remains some problems depending on what kind of components you have under you glasspane… I think that if you want rollover buttons you have to implement the

public void eventDispatched(AWTEvent event )

method from

AWTEventListener

interface.