-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.3.0
-
x86
-
windows_nt
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)
======================================================================
- duplicates
-
JDK-4290675 Focus Management Enhancements
-
- Closed
-