JDK-4799336 : REGRESSION: JPopupMenu focus bug, inconsistent behaviour
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-06
  • Updated: 2003-09-21
  • Resolved: 2003-09-21
Related Reports
Duplicate :  
Description

Name: jk109818			Date: 01/06/2003


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)

java version "1.4.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-b21)
Java HotSpot(TM) Client VM (build 1.4.1-b21, mixed mode)


FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
Under 1.4.x the behaviour of JPopupMenu is inconsistent, it
should be changed back to what is was under 1.3.1.

If the demo source code is run under 1.3.1 the popup will
always show, no matter which button is clicked or if the
popoup is closed by clicking outside its bounds or by
clicking the button it contains.

Problem 1:
Under 1.4.x if you click button 1 and then, while the popup
is still open, click button 2 the popup will close. If you
click on button 1 again however it will close and reopen.

Problem 2:
If you click on button 1 to open the popup, then click the
"close popup" button to close the popup button 1 will regain
focus if you click on button 2 (and the popup will not
show), this is extremely confusing for users.

Also note that problem 2 does not happen under the Windows
L&F as long as the popup contains at least one focusable
component.



REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Problem 1:
1. click "Button 1"
2. click "Button 2"
-> the popup closes

1. click "Button 1"
2. click "Button 1" again
-> the popup reopens

Problem 2:
1. click "Button 1" to open the popup
2. click the "close opopup" button to close the popup
3. click "Button 2"
-> "Button 1" regains focus, popup is not shown



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Demo extends JDialog implements ActionListener
{
	MyPopup pop = new MyPopup();

	public Demo(Frame f)
	{
		super(f);
		Container con = getContentPane();
		con.setLayout(new FlowLayout());
		for(int k = 1; k <= 2; k++) con.add(makeButton(k));
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setLocation(100,200);
		pack();
		setModal(true);
	}
	public void actionPerformed(ActionEvent ae)
	{
		System.out.println(((JButton)ae.getSource()).getText());
		pop.show((Component)ae.getSource(), 0, 20);
	}
	private JButton makeButton(int i)
	{
		JButton b = new JButton("Button " + i);
		b.addActionListener(this);
		return(b);
	}


	private class MyPopup extends JPopupMenu
	{
		public MyPopup() {
			JButton b = new JButton("close popup");
			b.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					setVisible(false);
				}
			});
			super.add(b);
			pack();
		}
	}


	public static void main(String[] args)
	{
		try	{
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
			//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
		}catch(Exception ex){  }

		JFrame f = new JFrame("ignore me");
		f.getContentPane().add(new JLabel(f.getTitle()));
		f.pack();
		f.show();

		new Demo(f).show();

		System.exit(0);
	}

}


---------- END SOURCE ----------

Release Regression From : 1.3.1_06
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: 165247) 
======================================================================

Comments
EVALUATION Name: azR10139 Date: 01/17/2003 This bug can be partially reproduced on current sources. Will be fixed in tiger. ###@###.### 1/17/2003 ====================================================================== The problem described more generally in bug 4912806. Since all the work is done in the bug 4912806, closing this bug as duplicate.
24-08-2004