-
Bug
-
Resolution: Fixed
-
P4
-
1.4.1, 6, 6u3, 6u10, 6u20
-
b105
-
x86
-
linux, windows_xp
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2204971 | 6u25 | Dmeetry Degrave | P2 | Closed | Fixed | b01 |
JDK-2204262 | 6u24-rev | Dmeetry Degrave | P2 | Resolved | Fixed | b22 |
JDK-2194872 | 6u22-rev | Dmeetry Degrave | P2 | Closed | Fixed | b07 |
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
I'm exploiting the new capability in JDK 1.4 to add a
PopupMenuListener to a JComboBox to populate the list just
before it is shown. When I click on the combo box to open
the popup list, the contents of the popup list looks fine,
but the size of the list is wrong. The size of the list is
apparently calculated from the previous number of entries in
the combo box model. It should use the new count of entries
instead. To get the popup list to size correctly, you must
close the popup list and open it again.
I reported this problem once before on 6/17/2002. It was
assigned an internal review ID of 153748. But I haven't
seen any further progress, and the bug doesn't show up in
the bug database, so I'm submitting it again.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the provided demonstration program.
2. Click on the arrow to open the popup list for the combo box.
3. Observe that the list is sized to show three items, which
is the OLD size of the list.
4. Close the popup list and open it again to observe that
the list is now sized for 8 items, the default maximum list
size.
EXPECTED VERSUS ACTUAL BEHAVIOR :
When opening the combo box, it is sized for 3 items, but the
list really contains 10 items. It should size the list for
8 items, the default maximum list size.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.event.*;
class ComboBug extends AbstractListModel implements ComboBoxModel,
PopupMenuListener {
JFrame f;
Object selected;
Object[] items;
public static void main(String[] args) {
new ComboBug();
}
ComboBug() {
f = new JFrame("Combo demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
items = new Object[] {"First", "Second", "Third"};
setSelectedItem(items[0]);
JComboBox combo = new JComboBox(this);
combo.addPopupMenuListener(this);
f.getContentPane().add(combo, BorderLayout.CENTER);
f.pack();
f.show();
}
public int getSize() {
return items.length;
}
public Object getElementAt(int index) {
return items[index];
}
public void setSelectedItem(Object obj) {
selected = obj;
fireContentsChanged(this, -1, -1); // Same as what DefaultComboBoxModel fires
}
public Object getSelectedItem() {
return selected;
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
int oldSize = items.length;
items = new Object[] {"One", "Two", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten"};
fireIntervalRemoved(this, 0, oldSize - 1);
fireIntervalAdded(this, 0, items.length - 1);
setSelectedItem(items[0]);
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {}
public void popupMenuCanceled(PopupMenuEvent e) {}
}
---------- END SOURCE ----------
(Review ID: 164152)
======================================================================
- backported by
-
JDK-2204262 Size of JComboBox list is wrong when list is populated via PopupMenuListener
- Resolved
-
JDK-2194872 Size of JComboBox list is wrong when list is populated via PopupMenuListener
- Closed
-
JDK-2204971 Size of JComboBox list is wrong when list is populated via PopupMenuListener
- Closed
- duplicates
-
JDK-6481846 REGRESSION:the size of popup menu was not correted with the new model when ComboBoxModel is changed
- Closed
-
JDK-6617411 Incorrect position of submenu of popup menu when submenu should be placed on left side of popup menu
- Closed
-
JDK-6766759 JComboBox menu can display incorrectly when manipulated from PopupMenuListener
- Closed
- relates to
-
JDK-7013330 javax/swing/Popup/TaskbarPositionTest.java failed on 1.6.0_23b20 but passed on 1.6.0_23b05
- Closed
-
JDK-7092300 Regression: Setting JComboBox popup location via PopupMenuListener fails
- Closed
-
JDK-6454037 Removing JComboBox during popupMenuWillBecomeVisible orphans popup
- Closed