JDK-6768307 : PIT : JComboBox's popup gets hidden below the heavy weight (AWT ) button
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6u12
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-11-06
  • Updated: 2011-01-19
  • Resolved: 2008-11-18
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 JDK 7
6u12Resolved 7Resolved
Related Reports
Duplicate :  
Relates :  
Description
I have a JFrame with widht & height of 300. I have added a JComboBox to the north of the frame & heavy weight (AWT ) button to the center of JFrame. When i click on the JComboBox . the popup menu is not seen. i,e the popup goes behind the AWT Button.   I tried resizing the frame to widht & height of 200 , then when i repeated the same scenario, the choice's popup is seen.    This is one of the common scenario, that can be tried after fixing the mixing of heavy weight & light weight components feature.


Step to reproduce :-
--------------------
1) Run the below testcase.
2) Click on the JComboBox, if you see the popup  , then the bug is reproduced. 

I tested this on 6u12 b01 pit build & jdk7 b38 promoted build.

=================== TestCase =======================
import javax.swing.*;
import java.awt.*;
import java.util.Vector;

public class TestLwComboBoxAndHwButton {

		JComboBox ch = null;
		JFrame frame = null;

		TestLwComboBoxAndHwButton(){
			frame = new JFrame();
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			Vector v = new Vector();
			for(int i = 1 ; i <=20;i++){
				v.add("Item # "+i);
			}
			ch = new JComboBox(v);
			frame.add(ch,BorderLayout.NORTH);
			frame.add(new Button("AWT Button"),BorderLayout.CENTER);
			frame.setSize(300,300);
			frame.setVisible(true);
		}

		public static void main(String []args) {
			javax.swing.SwingUtilities.invokeLater(new Runnable() {
					public void run()      {
						new TestLwComboBoxAndHwButton();
					}
			});
	}
}

====================================================

Comments
EVALUATION The original problem with the Swing ComboBox is a bit tougher. In fact, the javax.swing.PopupFactory.LightWeightPopup.reset() method retrieves the value of the opaque property from the combobox JPopupMenu (which is false) and assign this value to the container's (usually a PopupPane) opaque property, making it effectively non-opaque. Since the PopupPane is a plain JPanel, we can't use the 'implements OpaqueForMixing' approach in this case. Finally it seems that fixing this issue properly will involve fixing the 6637655 (Mixing of heavyweight/lightweight components does not wrk with GlassPane childre). In a nutshell, this RFE will enable considering opaque children in a non-opaque containers as opaque components for the mixing code. See the evaluation of 6637655 for more details.
11-11-2008

EVALUATION The best solution for this problem (which seems kind of a workaround, but still acceptable), is introducing a sun.awt.OpaqueForMixing interface. We need to make the JPopupMenu and JInternalFrame implement this interface. In the mixing code that verifies that the component is opaque we should use the following condition instead: (comp.isOpaque() || comp implements OpaqueForMixing) This way we avoid using the java.awt.Window.doesImplement() method which may bring performance degradation (especially when invoked twice for both JPopupMenu and JInternalFrame). Note: we avoid using direct instanceof for Swing classes since we don't want to introduce an additional dependency for the AWT library - otherwise a pure AWT application would require the Swing classes as well as the AWT.
10-11-2008

EVALUATION The combobox's popup is non-opaque by default. HW/LW Mixing code considers non-opaque components being naturally non-opaque - i.e. such components do not get cut off from the shape of the underlying heavyweight components. To fix this issue we should change all the checks isOpaque() in the HW/LW Mixing code to look like: (comp.isOpaque() || comp instanceof JPopupMenu). This seems to be the least risky fix.
07-11-2008