JDK-4765319 : 1.4 REGRESSION: Alt-Up/Down doens't open combo in WinLAF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7.0.0_01,1.4.0,1.4.2,5.0u12
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_9,windows_nt,windows_xp
  • CPU: x86,sparc
  • Submitted: 2002-10-18
  • Updated: 2005-08-31
  • Resolved: 2005-08-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b50Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
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 NT Version 4.0


A DESCRIPTION OF THE PROBLEM :
This is a list of the problems I encountered while using
JComboBox. Some have already been reported before but I am
putting it all together here in the hope someone will
notice.

1) There doesnt seem to be any way of cancelling the
selection made through the popup menu of the combo box.
PopupMenuListener.popupMenuCanceled() is never called.

2) The Up and Down arrow keys are supposed to navigate
through the popup menu of the combo box. What actually
happens is, the item gets selected and an ActionEvent is
fired(Placing the mouse on an item does not select it)

3) Placing the mouse on an item and then pressing the Enter
key does not select the item.

4) On Win32 platforms, pressing the Escape key after
navigating through the popup is supposed to restore the
original value. However, this does not happen because the
selection changes when we navigate.

5) On Win32 platforms, the Windows+F4 key is supposed to
toggle the popup menu. Java has no mapping for the Windows
key and so, nothing happens when this key combination is
pressed.

6) The API documentation says Alt+Up/Down is supposed to
toggle the menu. This does not happen when the look and
feel is Win32.

7) Editing a value fires two ActionEvents on the combo box.

8) Using the Enter key to select an item from the menu
first fires a PopupMenuEvent and then an ActionEvent. If
the mouse is used, the ActionEvent is fired first and then
the PopupMenuEvent.

9) The height of the "Files Of Type" combo box in the
JFileChooser dialog is greater than the height of the text
field and buttons when the look and feel is Win32.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the included the source code on a Win32 platform and
use a combination of the mouse and keyboard to edit and
select items. The print statements will print the events in
the order they occur.


REPRODUCIBILITY :
This bug can be reproduced always.

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

class BuggyComboBox extends JComboBox
{
	public BuggyComboBox()
	{
		super();

		setEditable(true);
		addItems();
		addListeners();
		setSelectedItem("Item 10");

		return;
	}

	protected void addListeners()
	{
		addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				System.out.println("Action performed!");

				return;
			}
		});

		addPopupMenuListener(new PopupMenuListener()
		{
			public void popupMenuWillBecomeVisible(PopupMenuEvent e)
			{
				System.out.println("Popup menu will become
visible!");

				return;
			}

			public void popupMenuWillBecomeInvisible(PopupMenuEvent
e)
			{
				System.out.println("Popup menu will become
invisible!");

				return;
			}

			public void popupMenuCanceled(PopupMenuEvent e)
			{
				System.out.println("Popup cancelled!");

				return;
			}
		});

		return;
	}

	protected void addItems()
	{
		addItem("Item 1");
		addItem("Item 2");
		addItem("Item 3");
		addItem("Item 4");
		addItem("Item 5");
		addItem("Item 6");
		addItem("Item 7");
		addItem("Item 8");
		addItem("Item 9");
		addItem("Item 10");

		return;
	}

	public static void main(String args[])
	{
		try
		{
			UIManager.setLookAndFeel
(UIManager.getSystemLookAndFeelClassName());
		}

		catch(Exception e)
		{}

		JFrame frame = new JFrame("Buggy Combo Box");
		BuggyComboBox comboBox = new BuggyComboBox();

		frame.addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent e)
			{
				System.exit(0);
			}
		});

		Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();

		comboBox.setBounds(25, 25, 100, 25);

		frame.getContentPane().setLayout(null);
		frame.getContentPane().add(comboBox);
		frame.setBounds((scrSize.width - 155) >> 1, (scrSize.height -
100) >> 1,
			155, 100);
		frame.setVisible(true);

		return;
	}
}

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

CUSTOMER WORKAROUND :
I added ActionListeners, KeyListeners and
PopupMenuListeners to the combo box and its editor and set
some flags to track where the call was coming from. Then,
based on the flags, I took appropriate action. But having
to do this every time is a real pain!
(Review ID: 159293) 
======================================================================

Comments
SUGGESTED FIX http://sa.sfbay.sun.com/projects/swing_data/mustang/4765319.1
17-08-2005

EVALUATION The submitter had detailed his grievances with the combo box. Many improvements have been done on JComboBox in 1.4.1 and 1.4.2. Evaluation which addressed items in numerical order: 1. This has been fixed for 1.4.2 under 4234793. 2. Using the up/down keys will select the items rather than navigate the entrys. Unfortunatly, these are the original semantics of combo box and cannot be chnaged. There is a sneaky work around: If you set the following client property on the combo box then it behaves like it's in a table and key navagation will not change the selection. putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); 3. Yes. This is a bug. 4. The semantics are the same as the combo boxes in Windows. Again, the semantics cannot change because of legacy issues. 5. This is an AWT issue. However, when AWT fixes this then JComboBox should be made aware. At the same time, the MS Windows User Experience guidelines does not document the WINDOWS-F4 binding. I don't think this should be fixed. 6. This is a REGRESSION in 1.4 beta 1 and should be fixed. 7. Yes. But they are two different ActionEvents. The getActionCommand shows that one event is comboBoxChanged and comboBoxEdited. 8. I can't seem to reproduce this in 1.4.2. The event semantics were cleaned up. A popup menu event will always be fired first. 9. This was addressed in 1.4.1 To summarize, only 3 and 6 are issues. 3) Placing the mouse on an item and then pressing the Enter key does not select the item. 6) The API documentation says Alt+Up/Down is supposed to toggle the menu. This does not happen when the look and feel is Win32. I'm downgrading the pritoriy since many of these issues have been addressed. ###@###.### 2002-10-18 I am not sure if it is a good idea to fix 3), because may be regressions will be possible. ###@###.### 2005-04-08 16:16:19 GMT Yes, problems 3) and 6) are bugs and should be fixed.
08-04-2005