JDK-4405206 : Bogus Mouse-Events if GlassPane is used
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2001-01-17
  • Updated: 2001-01-26
  • Resolved: 2001-01-26
Related Reports
Duplicate :  
Description

Name: boT120536			Date: 01/16/2001


1.3.0 final

/*
We want to use a GlassPane to catch all MouseEvents send to a frame.
The following program opens a small frame with one button.
If you press S, a GlassPane ist set. This should block MouseEvents
(you here a beep if you try to click th button).
If you press U, the GlassPane will be removed.

We see 2 problems:

1) press S to set the GlassPane
   click the button WITHOUT moving the mouse
   Result: the button gets the click

2) press U to unset the GlassPane
   click the button WITHOUT moving the mouse
   Result: the button gets NO click

If you move the mouse first, everything works fine.

We tried to find the bug. We think it happens because
the fix for bug 4155217 does not work.

This bug is VERY IMPORTANT for us.

*/

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Bug {

    public static void main(String[] args) {
        new Bug().go();
    }

    JFrame frame;

    Component blockingGlassPane = new BlockingGlassPane();

    Component oldGlassPane;

    public void go() {
        frame = new JFrame("Button");

        JButton button = new JButton("Click here!");
        button.addActionListener(
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    System.out.println("Clicked");
                }
            }
        );
        frame.getContentPane().add(button);

        // setGlassPane
          KeyStroke setKey = KeyStroke.getKeyStroke(KeyEvent.VK_S, 0);
          button.registerKeyboardAction(
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    frame.setGlassPane(blockingGlassPane);
                    blockingGlassPane.setVisible(true);
                    System.out.println("BlockinGlassPane set");
                }
            }
            , "setGlassPane", setKey, JComponent.WHEN_IN_FOCUSED_WINDOW
        );

        // unsetGlassPane
          KeyStroke unsetKey = KeyStroke.getKeyStroke(KeyEvent.VK_U, 0);
          button.registerKeyboardAction(
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    frame.setGlassPane(oldGlassPane);
                    System.out.println("BlockinGlassPane unset");
                }
            }
            , "unsetGlassPane", unsetKey, JComponent.WHEN_IN_FOCUSED_WINDOW
        );

        oldGlassPane = frame.getGlassPane();
        frame.pack();
        frame.setVisible(true);
    }
}

class BlockingGlassPane extends JComponent {

    public BlockingGlassPane() {
          enableEvents(AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK);
    }

     protected void processEvent(AWTEvent e) {
          if (e instanceof MouseEvent) {
               if (e.getID() == MouseEvent.MOUSE_CLICKED) {
                Toolkit.getDefaultToolkit().beep();
            }
        }
        super.processEvent(e);
     }
}
(Review ID: 113320) 
======================================================================

Comments
EVALUATION This sounds more like a problem with the LightweightDispatcher. scott.violet@eng 2001-01-17 Commit to fix in Merlin. eric.hawkes@eng 2001-01-23 Name: ssR10077 Date: 01/26/2001 The bug is not reproducible on 1.4.0-beta40 and later but still reproducible on 1.3.0 and 1.3.1-beta14 and 1.3.0. Looks like it is a focus bug and was fixed by putback of 4290675 (Focus Management Enhancements for merlin). ======================================================================
2004-06-11

WORK AROUND Name: boT120536 Date: 01/16/2001 Did not find one. ======================================================================
2004-06-11