-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.4.1
-
x86
-
windows_2000
Name: jk109818 Date: 12/10/2002
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
A DESCRIPTION OF THE PROBLEM :
Whenever a combo box is not entirely contained in the screen (i.e. its rectangle is not entirely contained in the
Rectangle returned by Toolkit.getDefaultToolkit().getScreenSize()), it systematically pops upward, regardless of its
vertical position.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Any window that contains a combo box can be used. Just drag the window partially out of the screen, so that
the combo box partially goes off the screen too. The program included below shows the exact problem.
2. Click on the combo box to display its popup.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If the vertical space below the combo box is sufficient to completely display the popup (at least, according to its
height), the popup should be displayed downward.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.event.*;
import javax.swing.*;
public class ComboPopupTest extends JFrame {
public ComboPopupTest() {
super("Combo Popup Test");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JComboBox cb = new JComboBox();
for (int i = 0; i < 20; i++)
cb.addItem("Item " + i);
getContentPane().add(cb);
pack();
}
public static void main(String[] args) {
JFrame fr = new ComboPopupTest();
// This positioning makes the combo box only partially visible on the screen.
// If I left the frame at (0, 0) or positioned it, for example, at the centre of the screen, the bug would not occur.
fr.setLocation(-20, 0);
fr.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
In my class extending BasicComboPopup, I overrided computePopupBounds(...) as follows. I modified the use of
SwingUtilities.isRectangleContainingRectangle(...) to use only its y-axis part.
protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
Rectangle rect = new Rectangle(px, py, pw, ph);
Point p = new Point();
GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
Rectangle absBounds;
SwingUtilities.convertPointFromScreen(p, comboBox);
if (gc != null) {
absBounds = gc.getBounds();
absBounds.x += p.x;
absBounds.y += p.y;
} else {
absBounds = new Rectangle(p, Toolkit.getDefaultToolkit().getScreenSize());
}
//if (!SwingUtilities.isRectangleContainingRectangle(absBounds, rect) && ph < absBounds.height)
if (!(rect.y >= absBounds.y && rect.y + rect.height <= absBounds.y + absBounds.height) && ph <
absBounds.height)
rect.y = -rect.height;
return rect;
}
(Review ID: 178976)
======================================================================
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
ADDITIONAL OPERATING SYSTEMS :
A DESCRIPTION OF THE PROBLEM :
Whenever a combo box is not entirely contained in the screen (i.e. its rectangle is not entirely contained in the
Rectangle returned by Toolkit.getDefaultToolkit().getScreenSize()), it systematically pops upward, regardless of its
vertical position.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Any window that contains a combo box can be used. Just drag the window partially out of the screen, so that
the combo box partially goes off the screen too. The program included below shows the exact problem.
2. Click on the combo box to display its popup.
3.
EXPECTED VERSUS ACTUAL BEHAVIOR :
If the vertical space below the combo box is sufficient to completely display the popup (at least, according to its
height), the popup should be displayed downward.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no error messages.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.event.*;
import javax.swing.*;
public class ComboPopupTest extends JFrame {
public ComboPopupTest() {
super("Combo Popup Test");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
JComboBox cb = new JComboBox();
for (int i = 0; i < 20; i++)
cb.addItem("Item " + i);
getContentPane().add(cb);
pack();
}
public static void main(String[] args) {
JFrame fr = new ComboPopupTest();
// This positioning makes the combo box only partially visible on the screen.
// If I left the frame at (0, 0) or positioned it, for example, at the centre of the screen, the bug would not occur.
fr.setLocation(-20, 0);
fr.setVisible(true);
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
In my class extending BasicComboPopup, I overrided computePopupBounds(...) as follows. I modified the use of
SwingUtilities.isRectangleContainingRectangle(...) to use only its y-axis part.
protected Rectangle computePopupBounds(int px, int py, int pw, int ph) {
Rectangle rect = new Rectangle(px, py, pw, ph);
Point p = new Point();
GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
Rectangle absBounds;
SwingUtilities.convertPointFromScreen(p, comboBox);
if (gc != null) {
absBounds = gc.getBounds();
absBounds.x += p.x;
absBounds.y += p.y;
} else {
absBounds = new Rectangle(p, Toolkit.getDefaultToolkit().getScreenSize());
}
//if (!SwingUtilities.isRectangleContainingRectangle(absBounds, rect) && ph < absBounds.height)
if (!(rect.y >= absBounds.y && rect.y + rect.height <= absBounds.y + absBounds.height) && ph <
absBounds.height)
rect.y = -rect.height;
return rect;
}
(Review ID: 178976)
======================================================================