Community
Participate
Working Groups
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(); } }
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.
Created attachment 69183 [details] Revised example source with root pane
Gordon, Great work and thanks for the input. I've dnlded the most recent doc and have read through it several times. :)
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.