Bug 170962 - JPopupMenu never receives focus
Summary: JPopupMenu never receives focus
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.2.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-18 14:51 EST by kevin miles CLA
Modified: 2019-09-06 16:16 EDT (History)
2 users (show)

See Also:


Attachments
Revised example source with root pane (4.71 KB, application/octet-stream)
2007-05-29 18:29 EDT, Gordon Hirsch CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description kevin miles CLA 2007-01-18 14:51:34 EST
I have a testcase below to show the problematic behavior mentioned above. 
-3.2RC7, Version: 3.2.1,  Build id: M20060921-0945
-java version "1.5.0_10"

I have a JPopupMenu on a Swing JTable that is within a SWT Shell. The JPopupMenu displays itself fine but it never accepts focus so that you can traverse the popup items with the up-down arrows or use mnemonics.


package org.dumb.junk;

import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;

public class SWTAWTTest
{

	Display swtDisplay;

	Shell swtShell;

	public SWTAWTTest()
	{
	}

	public void init()
	{

		swtDisplay = new Display();
		swtShell = new Shell(swtDisplay);
		swtShell.setSize(400, 200);
		swtShell.setLayout(new FillLayout());

		Label swtLabel = new Label(swtShell, SWT.NONE);
		swtLabel.setText("SWT Label");
		swtLabel.setToolTipText("SWT Label");

		Button swtButton = new Button(swtShell, SWT.NONE);
		swtButton.setText("SWT Button");
		swtButton.setToolTipText("SWT Button");

		Table swtTable = new Table(swtShell, SWT.BORDER);
		swtTable.setHeaderVisible(true);
		swtTable.setLinesVisible(true);
		swtTable.setToolTipText("SWT Table");

		Composite swtComposite = new Composite(swtShell, SWT.NO_BACKGROUND
				| SWT.EMBEDDED);
		Frame swingFrame = SWT_AWT.new_Frame(swtComposite);
		final JTable swingTable = new JTable(5, 5);

		swingTable.addMouseListener(new MouseAdapter()
		{
			public void mouseClicked(MouseEvent e)
			{
				if (e.getButton() != 3)
					return;

				JPopupMenu popup = new JPopupMenu();
				
				JMenuItem menuItem1 = new JMenuItem("Big DUMMY!");
				
				menuItem1.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent e)
					{
						System.out.println("Big DUMMY!");
					}
				});
				
				popup.add(menuItem1);
				
				JMenuItem menuItem2 = new JMenuItem("Big HEAD!");
				
				menuItem2.addActionListener(new ActionListener()
				{
					public void actionPerformed(ActionEvent e)
					{
						System.out.println("Big HEAD!");
					}
				});
				
				popup.add(menuItem2);
				
				popup.show(swingTable, e.getX(), e.getY());

			}
		});

		JScrollPane scrollPane = new JScrollPane(swingTable);

		swingFrame.add(scrollPane);

		swtShell.open();

		while (!swtShell.isDisposed())
		{
			if (!swtDisplay.readAndDispatch())
				swtDisplay.sleep();

		}

		swtDisplay.dispose();

	}

	public static void main(String[] args)
	{

		SWTAWTTest test = new SWTAWTTest();

		test.init();

	}

}
Comment 1 Gordon Hirsch CLA 2007-05-29 18:28:22 EDT
Kevin, sorry for butting in, but the problem here might be the fact that the example code is not setting up a proper Swing root pane container inside the frame. Swing event handling does not work very well if you don't do this. I'll attach a revised version of your code that creates a quick and dirty root pane and which does not have the focus problem, at least not for me. 

For details, take a look at bug 154973. That bug has a proposed article for eclipse.org that talks about this issue and many other steps necessary to get reasonably behaved embedded swing components.
Comment 2 Gordon Hirsch CLA 2007-05-29 18:29:18 EDT
Created attachment 69183 [details]
Revised example source with root pane
Comment 3 kevin miles CLA 2007-05-30 09:46:40 EDT
Gordon, 
Great work and thanks for the input. I've dnlded the most recent doc and have read through it several times. :)
Comment 4 Eclipse Webmaster CLA 2019-09-06 16:16:45 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.