SWT_AWT Popup menu problem [message #327969] |
Sat, 10 May 2008 14:19  |
Eclipse User |
|
|
|
Originally posted by: asf14.yahoo.com
Hi
I've been stuck on this problem for a while. I am writing an graph
editor using jgraph as an eclipse editor plugin. I use SWT_AWT.newFrame
to attach the swing component onto eclipse. My problem now is how to
implement popup menus associated with mouse clicks.
When I simply create a SWT menu when a mouse right click occurs, I get a
org.eclipse.swt.SWTException: Invalid thread access.
I tried to pass the composite from the SWT_AWT.newFrame(composite) and run
composite.getShell().getDisplay().syncExec( new Runnable() {
public void run(){
Menu menu = new Menu(composite.getShell());
etc etc
}
}
I still get a thread error msg
Does anyone know how to approach this problem ?
Any help will be greatly appreciated,
David
|
|
|
|
Re: SWT_AWT Popup menu problem [message #327971 is a reply to message #327969] |
Sat, 10 May 2008 16:32  |
Eclipse User |
|
|
|
composite.getShell() also cannot be called from a non-SWT thread, so as
Alessandro suggested, use Display.getDefault(). (Display.getCurrent() is
another option)
Also, it would be much better to call Display.asyncExec instead of
syncExec to avoid deadlock risk.
There are some issues in using popup menus in a mixed Swing/SWT
environment. You might want to look into the Albireo project
(http://www.eclipse.org/albireo - currently in alpha) which provides
specific support for SWT popups on a Swing control, among other things.
You also might be interested in the Swing/SWT integration article here:
http://www.eclipse.org/articles/article.php?file=Article-Swi ng-SWT-Integration/index.html
Dave wrote:
> Hi
>
> I've been stuck on this problem for a while. I am writing an graph
> editor using jgraph as an eclipse editor plugin. I use SWT_AWT.newFrame
> to attach the swing component onto eclipse. My problem now is how to
> implement popup menus associated with mouse clicks.
>
> When I simply create a SWT menu when a mouse right click occurs, I get a
> org.eclipse.swt.SWTException: Invalid thread access.
>
> I tried to pass the composite from the SWT_AWT.newFrame(composite) and run
>
> composite.getShell().getDisplay().syncExec( new Runnable() {
>
> public void run(){
>
> Menu menu = new Menu(composite.getShell());
> etc etc
>
> }
>
> }
>
> I still get a thread error msg
>
> Does anyone know how to approach this problem ?
>
> Any help will be greatly appreciated,
> David
|
|
|
Powered by
FUDForum. Page generated in 0.03174 seconds