SWT Threads [message #630986] |
Tue, 05 October 2010 14:39  |
Eclipse User |
|
|
|
I am creating an application in Java with SWT where I have a main shell from where I can open several other shells. Each new shell is created in a new thread and opened from a button on the main shell.
But when one of the other shells is working, the other shells is unresponsive.
The code is something like the following code but when I press the button, a new shell is created and opened. I just created this to show that the list isn't updating when clicking in it while the other thread is working.
Is there a way to make the other shells responsive while one shell is working?
package threadtest;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
public class Main extends Shell
{
List list = new List (this, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
Button buttonStart = new Button(this, SWT.NONE);
public static void main(String[] args)
{
Main main = new Main();
}
Main()
{
super(Display.getDefault(), SWT.CLOSE | SWT.TITLE | SWT.MIN);
this.setText("ThreadTest");
this.setBounds(150, 150, 200, 340);
buttonStart.setText("Start");
buttonStart.setLocation(100, 270);
buttonStart.pack();
buttonStart.addSelectionListener(startListener);
list.setBounds(10, 10, 150, 250);
for (int index = 0; index < 10; index++)
list.add("Item " + index);
this.open();
while (!this.isDisposed())
{
if (!Display.getDefault().readAndDispatch())
Display.getDefault().sleep();
}
}
@Override
protected void checkSubclass()
{
// Disable the check that prevents subclassing of SWT components
}
SelectionListener startListener = new SelectionListener()
{
@Override
public void widgetSelected(SelectionEvent event)
{
Thread threadStart;
threadStart = new Thread(startRunnable);
threadStart.start();
}
@Override
public void widgetDefaultSelected(SelectionEvent event)
{
}
};
Runnable startRunnable = new Runnable()
{
@Override
public void run()
{
Display.getDefault().asyncExec (new Runnable ()
{
@Override
public void run ()
{
for (int index = 0; index < 100000; index++)
System.out.println("index: " + index);
System.out.println("Done");
}
});
}
};
}
|
|
|
|
|
Re: SWT Threads [message #631049 is a reply to message #631007] |
Tue, 05 October 2010 19:53  |
Eclipse User |
|
|
|
On Tue, 2010-10-05 at 22:00 +0200, larsk wrote:
> Thanks for your answer!
>
> The above code was just an example. In the real code I am updating/accessing some SWT components. I just didn't want to post the whole code.
> How should I do if I want to update a shell and still be able to use another shell?
Simply create the second shell. The SWT Display thread will handle both
shells.
|
|
|
Powered by
FUDForum. Page generated in 0.05432 seconds