Name: sv35042 Date: 10/18/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
FULL OPERATING SYSTEM VERSION :Windows 2000
A DESCRIPTION OF THE PROBLEM :
When compile and run the application with JPopupMenu in
JDK1.4.0,
the first mouse click event is missed right after the popup
menu set to invisible. Have to mouse click again to get the
mouse click event. The same code works fine in JDK1.2.2.
REGRESSION. Last worked in version 1.2.2
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Run the sample program provide here using jdk1.4.
2.Click "Pop" button on the top of the window.
3.The Popup Menu shows with Click option.
4.Select Click, the Popup menu hides.
5.Mouse click on "Cut" button on the bottom of the window.
6.Look at the DOS command prompt, the debug code in
actionPerformed(ActionEvent e) "Got the action" does not
showed.The mouse event is missed.
7.Click the "Cut" button again, the "Got the action" shows
in the DOS window.
For the same code when you do javac & run under JDK1.2.2,
the step 6 shows the debug code in DOS window.
EXPECTED VERSUS ACTUAL BEHAVIOR :
When click the "Cut" button right after clicking "Click" on
the popup menu, the actionPerformed() should be called.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Observer;
import java.util.Observable;
// java core classes needed
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.Icon;
import javax.swing.JPopupMenu;
import javax.swing.JLabel;
import javax.swing.BorderFactory;
import javax.swing.SwingConstants;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import javax.swing.JWindow;
import javax.swing.JTextField;
import javax.swing.JFrame;
public class Bug extends JPanel
implements ActionListener, MouseListener {
private JPopupMenu popup = null;
private JButton cutB = null;
private JButton selB = null;
private JLabel clickL = null;
/**
* Basic constructor.
*/
public Bug(){
super(new BorderLayout());
setPreferredSize(new java.awt.Dimension(240,20));
clickL = new JLabel("Click");
clickL.addMouseListener(this);
cutB = new JButton("Cut");
cutB.addActionListener(this);
cutB.setActionCommand("CUT");
selB = new JButton("Pop");
selB.addActionListener(this);
selB.setActionCommand("POP");
popup = new JPopupMenu();
popup.setLayout(new BorderLayout());
popup.setBorder(null);
popup.setPreferredSize(new java.awt.Dimension((int)getPreferredSize
().getWidth(),
(int)getPreferredSize
().getWidth()));
add(selB,BorderLayout.NORTH);
add(cutB,BorderLayout.SOUTH);
popup.add(clickL);
}
/* May be needed later on.*/
public void mouseEntered(MouseEvent event){ System.out.println("Enteredt");
popup.dispatchEvent(new MouseEvent(popup, MouseEvent.MOUSE_CLICKED, 1000,
0, 2, 2, 1, false));
}
public void mouseExited(MouseEvent event){System.out.println("Exited");}
public void mousePressed(MouseEvent event){ System.out.println("Pressed");}
public void mouseReleased(MouseEvent event){
System.out.println("Released");
}
public void mouseClicked(MouseEvent event){
System.out.println("Clicked");
popup.setVisible(false);
}
/** See ActionListener comments. */
public void actionPerformed(ActionEvent e) {
System.out.println("Got the action.");
if (e.getActionCommand().equals("POP")) {
popup.show(this, 0,this.getHeight());
} else if (e.getActionCommand().equals("CLOSE")) {
popup.setVisible(false);
}
}
public static void main(String args[]) {
JPanel p = new Bug();
JFrame frame = new JFrame("Testing...");
frame.setBounds(300,50,400,400);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(p,"Center");
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0); }}
);
frame.setVisible(true);
frame.show();
}
}
---------- END SOURCE ----------
Release Regression From : 1.4
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Review ID: 147215)
======================================================================