JDK-4128118 : JPopupMenu/JComboBox popup weight in Beans
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.5
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1998-04-11
  • Updated: 1998-06-01
  • Resolved: 1998-06-01
Related Reports
Duplicate :  
Description

Name: rk38400			Date: 04/11/98


This is a similar problem to bug 4114618 - but this is being dismissed as an AWT Z-ordering problem on Solaris.

Try the following bean out in the BeanBox (or in Visual Cafe.)

import com.sun.java.swing.*;
import java.awt.*;
import java.awt.event.*;

public class RootBean extends JPanel
{
	JButton b;
	JComboBox c;

	public Container getContentPane()
	{
		return this; //super.getContentPane();
	}

	public RootBean()
	{
		getContentPane().setLayout(new BorderLayout());

		b = new JButton("Hello");
		b.addActionListener(
			new ActionListener()
			{
				public void actionPerformed(ActionEvent e)
				{
					JPopupMenu pop = new JPopupMenu();
					pop.setLightWeightPopupEnabled(false);
					for (int i = 0; i < 10; i++)
					{
						pop.add(new JMenuItem("Stuff" + i));
					}
					pop.show(b, 0, 0);
				}	
			});
		getContentPane().add(BorderLayout.CENTER, b);

		c = new JComboBox();
		c.setLightWeightPopupEnabled(false);
		for (int i = 0; i < 10; i++)
		{
			c.addItem("Stuff" + i);
		}
		getContentPane().add(BorderLayout.SOUTH, c);
	}
}

In the beanbox, the popups only draw correctly if the bean is close enough to the edge of the BeanBoxFrame
such that JPopupMenu's popupFits() method returns false and forces creation of a HeavyWeight popup.
Mediumweight popups will not show when added to the BeanBoxFrame.

I can make the bean a subclass of JRootPane, but then my popups will (in the Beanbox) be clipped to
the bean's bounds. In other cases (such as a Visual Cafe app) they might paint correctly but mouse tracking
doesn't function properly.

It might be possible to fix BeanBox so it does the right thing - but what I'm getting at here is that a Bean
cannot really guarantee that it's container will be friendly to Swing's light and mediumweight popups -
and there needs to be a way of forcing use of heavyweight popups in all cases.
(Review ID: 26367)
======================================================================

Comments
EVALUATION I started by trying this simple program to confirm that setLightWeightPopupEnabled(false) does work for JComboBox. import com.sun.java.swing.*; import com.sun.java.swing.border.*; import java.awt.*; class Scratch extends JFrame { public static void main( String args[] ) { JFrame f = new JFrame(); Panel p = new Panel(); p.setLayout(new FlowLayout()); Object[] items = { "Hi", "There", "Bob" }; JComboBox jcb = new JComboBox(items); jcb.setLightWeightPopupEnabled(false); p.add(jcb); f.getContentPane().add(p, BorderLayout.CENTER); f.pack(); f.show(); } } It puts the combobox inside a Panel (which is heavy). Everything seems to work fine. However, I dropped a JComboBox into the BeanBox, and couldn't get it to popup except as a heavy-wieght. I'm somewhat confused. I'll come back to this later. steve.wilson@eng 1998-05-21
21-05-1998