JDK-4337516 : JComboBox popup doesn't initially display selected item
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0,1.3.1,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_8,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 2000-05-11
  • Updated: 2000-11-17
  • Resolved: 2000-11-17
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.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Description

Name: stC104175			Date: 05/11/2000


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

Set a selected index in a JComboBox.
click on the combo box.
The scroll box appears at the top and the selected item isn't visible.
Scrolling down shows the correct item as highlighted.

click again (twice) to hide/show the list.
The correct, selected item is now shown.
As can be seen, the combo box doesn't initially scroll to the right position.

(In example below should show 2000, but only shows 1900, 1901...)

package test;
import javax.swing.*;
import java.util.Vector;
public class YearTest extends JFrame
{
	public YearTest()
	{
		Vector years = new Vector();
		for (int i=0;i<200;i++)
		{
			years.add(new Integer(i+1900));
		}
		JComboBox yearCombo = new JComboBox(years);
		yearCombo.setSelectedIndex(100);
		getContentPane().add(yearCombo);
		setSize(300,300);
	}
	public static void main(String [] args)
	{
		YearTest test = new YearTest();
		test.setDefaultCloseOperation(EXIT_ON_CLOSE);
		test.setVisible(true);
	}
}
(Review ID: 104720) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION I've verified that this has been a regression that was introduced between 1.2.2 and 1.3.beta. It appears that something may have changed within BasicComboPopup version 1.23 99/04/22 and 1.32 00/02/02. I'm guessing that the change may have been a result of the added BIDI support. It appears that the list.ensureIndexIsVisible() method is either not called or circumstances do not allow the contents to be updated. The combo box is a really complex component which needs to be simplified. Still investigating. mark.davidson@Eng 2000-08-04 This problem doesn't seem to be limited to the combo box. It appears that the fix to JViewport version 1.61.1.2 as a result of the fix for 4217252 may have caused JList.ensureIndexIsVisible() to fail. There seems to be quite a bit of diffs for JViewport.scrollRectToVisible(Rectangle) in 1.61.1.2 Here's the modified test case: >>>>>> YearTest.java /* java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode) Set a selected index in a JComboBox. click on the combo box. The scroll box appears at the top and the selected item isn't visible. Scrolling down shows the correct item as highlighted. click again (twice) to hide/show the list. The correct, selected item is now shown. As can be seen, the combo box doesn't initially scroll to the right position. (In example below should show 2000, but only shows 1900, 1901...) */ import javax.swing.*; import java.awt.BorderLayout; import java.util.Vector; public class YearTest extends JFrame { public YearTest() { Vector years = new Vector(); for (int i=0;i <= 100; i++) { years.add(new Integer(i+1900)); } JComboBox yearCombo = new JComboBox(years); yearCombo.setSelectedIndex(100); JComboBox yearCombo2 = new JComboBox(years); yearCombo2.setSelectedIndex(7); JComboBox yearCombo3 = new JComboBox(years); yearCombo3.setSelectedIndex(9); JPanel panel = new JPanel(); panel.add(yearCombo); panel.add(yearCombo2); panel.add(yearCombo3); JList list = new JList(years); JScrollPane scroll = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); list.setSelectedIndex(100); list.ensureIndexIsVisible(100); JList list2 = new JList(years); JScrollPane scroll2 = new JScrollPane(list2, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); list2.setSelectedIndex(7); list2.ensureIndexIsVisible(7); JList list3 = new JList(years); JScrollPane scroll3 = new JScrollPane(list3, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER ); list3.setSelectedIndex(9); list3.ensureIndexIsVisible(9); JPanel panel2 = new JPanel(); panel2.add(scroll); panel2.add(scroll2); panel2.add(scroll3); getContentPane().add(panel, BorderLayout.NORTH); getContentPane().add(panel2, BorderLayout.CENTER); setSize(300,400); } public static void main(String [] args) { YearTest test = new YearTest(); test.setDefaultCloseOperation(EXIT_ON_CLOSE); test.setVisible(true); } } <<<<< YearTest.java mark.davidson@Eng 2000-10-13 This is happening because of the fix for 4217252. JViewport will not allow you to scroll beyond the bounds of the component (at least through scrollRectToVisible). JComboBox (actually BasicComboPopup) invokes scrollRectToVisible before the containment hiearchy is valid. As such, the size of the list is 0x0, and JViewport.scrollRectToVisible will not allow the scrolling. As it seems reasonable to want to scroll before the containment hiearchy is valid, JViewport will now only constrain the scrolling the if the view is valid. If this view isn't valid, it allows the scrolling regardless. scott.violet@eng 2000-10-24
24-10-2000