Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » org.eclipse.swt.SWTException: Invalid thread access
org.eclipse.swt.SWTException: Invalid thread access [message #459417] Tue, 09 August 2005 12:19 Go to next message
Eclipse UserFriend
Originally posted by: kruttik.a.tcs.com

Hi
I want to create a simple UI for user on calling the run method of my
action class in Eclipse 3.0.
public void run(IAction arg0) {
try{
Display display = new Display();
Shell shell1 = new Shell(display);
shell1.setLayout( new RowLayout());
MessageBox messageBox = new MessageBox(shell1, SWT.OK|SWT.CANCEL);
if (messageBox.open() == SWT.OK)
{
System.out.println("Ok is pressed.");
}
shell1.pack();
shell1.open();
while( !shell1.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
catch(Exception e){
MessageDialog.openInformation(shell,"Hello World","In Error:
"+e.getMessage());
e.printStackTrace();
}
}
However i am getting
org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(SWT.java:2691)
at org.eclipse.swt.SWT.error(SWT.java:2616)
at org.eclipse.swt.SWT.error(SWT.java:2587)
at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:56 8)
at org.eclipse.swt.widgets.Display.create(Display.java:629)

I am confused, since most of the forum say that this error happens in
multi-threaded processes, but mine is not a threaded app.
Please help as I am new to SWT and eclipse
Re: org.eclipse.swt.SWTException: Invalid thread access [message #459460 is a reply to message #459417] Tue, 09 August 2005 13:14 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Kruttik,

You do not need to create a new Display here since one already exists
(created by Eclipse). The best parent for your MessageBox is the workbench
Shell, which you will need to compute. Computing this is of course
context-dependent, but if for instance your action class implements
IWorkbenchWindowActionDelegate, then you can invoke getShell() on the
IWorkbenchWindow that is passed to your init(...) method.

Also, you will not need the lines from shell1.pack() onwards because
messageBox.open() runs its own event loop, and after the user has pressed OK
you should just let control return to the platform (you do not need to run
your own event loop here).

Grant

"Kruttik Aggarwal" <kruttik.a@tcs.com> wrote in message
news:005d3758896fa42d46979f97b2f5641b$1@www.eclipse.org...
> Hi
> I want to create a simple UI for user on calling the run method of my
> action class in Eclipse 3.0.
> public void run(IAction arg0) {
> try{
> Display display = new Display();
> Shell shell1 = new Shell(display);
> shell1.setLayout( new RowLayout());
> MessageBox messageBox = new MessageBox(shell1, SWT.OK|SWT.CANCEL);
> if (messageBox.open() == SWT.OK)
> {
> System.out.println("Ok is pressed.");
> }
> shell1.pack();
> shell1.open();
> while( !shell1.isDisposed())
> {
> if(!display.readAndDispatch())
> display.sleep();
> }
> display.dispose();
> }
> catch(Exception e){
> MessageDialog.openInformation(shell,"Hello World","In Error:
> "+e.getMessage());
> e.printStackTrace();
> }
> }
> However i am getting
> org.eclipse.swt.SWTException: Invalid thread access
> at org.eclipse.swt.SWT.error(SWT.java:2691)
> at org.eclipse.swt.SWT.error(SWT.java:2616)
> at org.eclipse.swt.SWT.error(SWT.java:2587)
> at org.eclipse.swt.widgets.Display.checkDisplay(Display.java:56 8)
> at org.eclipse.swt.widgets.Display.create(Display.java:629)
>
> I am confused, since most of the forum say that this error happens in
> multi-threaded processes, but mine is not a threaded app.
> Please help as I am new to SWT and eclipse
>
Previous Topic:How can i set the BackgroundColor of the Selected item?
Next Topic:How to prevent stretching of images in swt table
Goto Forum:
  


Current Time: Thu Apr 25 07:35:40 GMT 2024

Powered by FUDForum. Page generated in 0.02600 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top