Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!86597e80!not-for-mail From: "Richard" Subject: Re: Swing embedded in SWT Message-ID: <1168011152.725860.271530@s80g2000cwa.googlegroups.com> X-Comment-To: comp.lang.java.gui Newsgroups: comp.lang.java.gui In-Reply-To: <1167937309.866198.186320@6g2000cwy.googlegroups.com> References: <1167937309.866198.186320@6g2000cwy.googlegroups.com> Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.15a-Win32 NewsLink 1.92] Lines: 115 Date: Wed, 27 Apr 2011 15:28:18 GMT NNTP-Posting-Host: 96.60.20.240 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1303918098 96.60.20.240 (Wed, 27 Apr 2011 10:28:18 CDT) NNTP-Posting-Date: Wed, 27 Apr 2011 10:28:18 CDT Organization: TDS.net Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:572 To: comp.lang.java.gui As I followup to this, I ran this using JRE v1.5 and it worked fine. This DOESN"T work in JRE v1.4.2. Does anyone know of a workaround in JRE v1.4.2? I can't move to JRE v1.5 at this time. rjkoop@gmail.com wrote: > I'm having problems when I embed an Swing component within an SWT > composite. Inside the Swing component I have a JTable that contains a > JPopupMenu. The popup menu comes up fine when I right mouse click and > go does correctly if I click anywhere inside the Swing component but > DOESN"T dissapear when I click on an SWT appear of the application. > >From what I've read I'm doing it correctly. Is this a bug in > Eclipse/SWT? I'm using the Eclipse 3.2.1 and the associated SWT 3.2.1. > > Here's a simple block of code that can be used to reproduce the > problem. Am I doing something wrong? Or do I have to manually code > the popdown of the Swing JPopupMenu from the SWT thread? > > /* > * Created on 20-Apr-06 > * > */ > package mine.app; > > import java.awt.BorderLayout; > import java.awt.Frame; > import java.awt.Panel; > 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.JRootPane; > 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.Shell; > import org.eclipse.swt.widgets.Table; > > public class SWTAWTTest > { > public static void main(String[] args) > { > Display swtDisplay = new Display(); > Shell 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 menuItem = new JMenuItem("Select me"); > menuItem.addActionListener(new ActionListener() > { > public void actionPerformed(ActionEvent e) > { > } > }); > popup.add(menuItem); > 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(); > } > > } --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24