Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » GUI hanging.
GUI hanging. [message #447271] Sun, 12 December 2004 16:01 Go to next message
Matt McKenzie is currently offline Matt McKenzieFriend
Messages: 2
Registered: July 2009
Junior Member
--____LPHMXLZMXOMRLFKSEJCW____
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi

I am new to java programing and even newer to SWT programming. I have =
found a problem where the GUI interface will "Hang". The background =
processes are all working but the GUI stops updating. (Running in a =
Windows XP environment)

I do not know if this is bug or a problem with my code. Below is a sample =
program that demonstrates the problem.

The program outputs a number to a text box and at the same time printing =
it to the system console. It is in a simple for loop. When the program is =
running press in quick succession the mouse about 10 to 20 times, The GUI =
will hang, however the System console is still being updated.

Is this a bug, or is their another way to do this.

I would be most gratefull for any assistance.

Thanks

Matt

Sample program

public class Temp {

public static void main(String[] args) {
Temp t =3D new Temp();
t.start();
}
public void start(){
Display display =3D new Display();
Shell shell =3D new Shell(display);
Text text =3D new Text(shell,SWT.MULTI);
text.setSize(200,200);
text.setEditable(false);
shell.open();
=20
int y=3D1000000;
for (int x=3D0;x<y;x++){
text.append("\nCounter.. "+x);
System.out.print("\nCounter.. "+x);
}
=20
shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch())display.sleep();
}
display.dispose();
}
}

--____LPHMXLZMXOMRLFKSEJCW____
Content-Type: multipart/related; boundary="____WHPEPQYSAQXEHDGESJXG____"


--____WHPEPQYSAQXEHDGESJXG____
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1"=
>
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Hi</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am new to java programing and even newer to SWT programming. I have =
found a problem where the GUI interface will "Hang". The background =
processes are all working but the GUI stops updating. (Running in a =
Windows XP environment)</DIV>
<DIV>&nbsp;</DIV>
<DIV>I do not know if this is bug or a problem with my code. Below is a =
sample program that demonstrates the problem.</DIV>
<DIV>&nbsp;</DIV>
<DIV>The program outputs a number to a text box and at the same time =
printing it to the system console. It is in a simple for loop. When the =
program is running press in quick succession the mouse about 10 to 20 =
times, The GUI will hang, however the System console is still being =
updated.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Is this a bug, or is their another way to do this.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I would be most gratefull for any assistance.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks</DIV>
<DIV>&nbsp;</DIV>
<DIV>Matt</DIV>
<DIV>&nbsp;</DIV>
<DIV>Sample program</DIV>
<DIV>&nbsp;</DIV>
<DIV>public class Temp {</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;public static void main(String[] args) {<BR>&nbsp;&nbsp;Temp t =
=3D new Temp();<BR>&nbsp;&nbsp;t.start();<BR>&nbsp;} <BR>&nbsp;public void =
start(){<BR>&nbsp;&nbsp;Display display =3D new Display();<BR>&nbsp;&nbsp;S=
hell shell =3D new Shell(display);<BR>&nbsp;&nbsp;Text text =3D new =
Text(shell,SWT.MULTI);<BR>&nbsp;&nbsp;text.setSize(200,200); <BR>&nbsp;&nbsp=
;text.setEditable(false);<BR>&nbsp;&nbsp;shell.open(); <BR>&nbsp;&nbsp;<BR>&=
nbsp;&nbsp;int y=3D1000000;<BR>&nbsp;&nbsp;for (int x=3D0;x&lt;y;x++){<BR>&=
nbsp;&nbsp;&nbsp;text.append("\nCounter..&nbsp; "+x);<BR>&nbsp;&nbsp;&nbsp;=
System.out.print("\nCounter..&nbsp; "+x);<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;<=
BR>&nbsp;&nbsp;shell.open();<BR>&nbsp;&nbsp;while (!shell.isDisposed()){<BR=
>&nbsp;&nbsp;&nbsp;if (!display.readAndDispatch())display.sleep();<BR>&nbsp=
;&nbsp;}<BR>&nbsp;&nbsp;display.dispose();<BR >&nbsp;}<BR>}<BR></DIV></BODY>=
</HTML>

--____WHPEPQYSAQXEHDGESJXG____--

--____LPHMXLZMXOMRLFKSEJCW____--
Re: GUI hanging. [message #447272 is a reply to message #447271] Sun, 12 December 2004 17:39 Go to previous messageGo to next message
Mani Ghamari is currently offline Mani GhamariFriend
Messages: 33
Registered: July 2009
Member
Hi Matt,

Your "for" loop is a long-running process.

When you start clicking around while the loop is running, the mouse events
are queued directly in the SWT event queue, which must be processed by the
UI-Thread BEFORE any other GUI operations can be processed (e.g.
Text.append(String str) ).

So, the mouse events block the event queue, because the the event processing
code
(generally: display.readAndDispatch() never gets a chance to process and
execute (or in SWT terms, read and dispatch!) the queued events. (because
the programm just "STAYS" in your for loop, the whole time).

Here is a possible solution to the problem which I use often myself: I put
the update loop in a seperate Thread, so that the UI-Thread can process the
events without getting blocked. Note that display.syncExec() is used to pass
the UI-changing instructions back to the UI-Thread...

For more info, take a look at the API docs for:
org.eclipse.swt.widgets.Display
&
Display.syncExec(Runnable runnable)
Display.asyncExec(Runnable runnable)

you might also want to take a look at the articles found on these pages,
which both contain excellent tutorials for starters...:
http://www.eclipse.org/articles
http://www.cs.umanitoba.ca/~eclipse/

/* ***************** here is code********* */

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

public class Temp implements Runnable
{
// display and text are made global so that the references are available
within the run() method
Display display;
Text text;

// running is made global because otherwise it has to be declared final
to be accessible
// from the inner class
boolean running;

public void run()
{
int y=1000000;

// if running is false, the shell is disposed and the thread should
stop running
// the variable running is used to prevent an Text.append(String
str), after the text is
// disposed (otherwise .append() would throw a
WidgetDisposedException)

for (int x=0;x<y && running;x++)
{
final int x2 = x;

// All calls to the GUI must be made within the UI-thread
display.syncExec(new Runnable()
{
public void run()
{
if (!text.isDisposed())
{
// shell and text are still there: update
text.append("\nCounter.. "+x2);
System.out.print("\nCounter.. "+x2);
}
else
{
// shell and text are disposed: stop running...
running = false;
}
}
});
}
}

public static void main(String[] args)
{
Temp t = new Temp();
t.start();
}

public void start()
{

running = true;
display = new Display();
Shell shell = new Shell(display);
text = new Text(shell,SWT.MULTI);
text.setSize(200,200);
text.setEditable(false);
shell.open();

// shell is created, start the update thread...
Thread thread = new Thread(this);
thread.start();

// you dont need to open the shell twice...
// shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())display.sleep();
}
display.dispose();
}
}


regards,

Mani

"Matt McKenzie" <mmckenzie@novell.com> wrote in message
news:cphqhm$nt5$1@www.eclipse.org...
Hi

I am new to java programing and even newer to SWT programming. I have found
a problem where the GUI interface will "Hang". The background processes are
all working but the GUI stops updating. (Running in a Windows XP
environment)

I do not know if this is bug or a problem with my code. Below is a sample
program that demonstrates the problem.

The program outputs a number to a text box and at the same time printing it
to the system console. It is in a simple for loop. When the program is
running press in quick succession the mouse about 10 to 20 times, The GUI
will hang, however the System console is still being updated.

Is this a bug, or is their another way to do this.

I would be most gratefull for any assistance.

Thanks

Matt

Sample program

public class Temp {

public static void main(String[] args) {
Temp t = new Temp();
t.start();
}
public void start(){
Display display = new Display();
Shell shell = new Shell(display);
Text text = new Text(shell,SWT.MULTI);
text.setSize(200,200);
text.setEditable(false);
shell.open();

int y=1000000;
for (int x=0;x<y;x++){
text.append("\nCounter.. "+x);
System.out.print("\nCounter.. "+x);
}

shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch())display.sleep();
}
display.dispose();
}
}
Re: GUI hanging. [message #447284 is a reply to message #447272] Mon, 13 December 2004 09:15 Go to previous message
Matt McKenzie is currently offline Matt McKenzieFriend
Messages: 2
Registered: July 2009
Junior Member
--____LPHMXLZMXOMRLFKSEJCW____
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Mani

Thanks for the tips.

I will give to try.

Thanks

Matt

>>> Mani Ghamari<mani.ghamari@linkast.com> 12/12/2004 17:39:32 >>>

Hi Matt,

Your "for" loop is a long-running process.

When you start clicking around while the loop is running, the mouse =
events=20
are queued directly in the SWT event queue, which must be processed by =
the=20
UI-Thread BEFORE any other GUI operations can be processed (e.g.=20
Text.append(String str) ).

So, the mouse events block the event queue, because the the event =
processing=20
code
(generally: display.readAndDispatch() never gets a chance to process =
and=20
execute (or in SWT terms, read and dispatch!) the queued events. =
(because=20
the programm just "STAYS" in your for loop, the whole time).

Here is a possible solution to the problem which I use often myself: I =
put=20
the update loop in a seperate Thread, so that the UI-Thread can process =
the=20
events without getting blocked. Note that display.syncExec() is used to =
pass=20
the UI-changing instructions back to the UI-Thread...

For more info, take a look at the API docs for:
org.eclipse.swt.widgets.Display
&
Display.syncExec(Runnable runnable)
Display.asyncExec(Runnable runnable)

you might also want to take a look at the articles found on these =
pages,=20
which both contain excellent tutorials for starters...:
http://www.eclipse.org/articles
http://www.cs.umanitoba.ca/~eclipse/

/* ***************** here is code********* */

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

public class Temp implements Runnable
{
// display and text are made global so that the references are =
available=20
within the run() method
Display display;
Text text;

// running is made global because otherwise it has to be declared =
final=20
to be accessible
// from the inner class
boolean running;

public void run()
{
int y=3D1000000;

// if running is false, the shell is disposed and the thread =
should=20
stop running
// the variable running is used to prevent an Text.append(String=20=

str), after the text is
// disposed (otherwise .append() would throw a=20
WidgetDisposedException)

for (int x=3D0;x<y && running;x++)
{
final int x2 =3D x;

// All calls to the GUI must be made within the UI-thread
display.syncExec(new Runnable()
{
public void run()
{
if (!text.isDisposed())
{
// shell and text are still there: update
text.append("\nCounter.. "+x2);
System.out.print("\nCounter.. "+x2);
}
else
{
// shell and text are disposed: stop running...
running =3D false;
}
}
});
}
}

public static void main(String[] args)
{
Temp t =3D new Temp();
t.start();
}

public void start()
{

running =3D true;
display =3D new Display();
Shell shell =3D new Shell(display);
text =3D new Text(shell,SWT.MULTI);
text.setSize(200,200);
text.setEditable(false);
shell.open();

// shell is created, start the update thread...
Thread thread =3D new Thread(this);
thread.start();

// you dont need to open the shell twice...
// shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())display.sleep();
}
display.dispose();
}
}


regards,

Mani

"Matt McKenzie" <mmckenzie@novell.com> wrote in message=20
news:cphqhm$nt5$1@www.eclipse.org...
Hi

I am new to java programing and even newer to SWT programming. I have =
found=20
a problem where the GUI interface will "Hang". The background processes =
are=20
all working but the GUI stops updating. (Running in a Windows XP=20
environment)

I do not know if this is bug or a problem with my code. Below is a =
sample=20
program that demonstrates the problem.

The program outputs a number to a text box and at the same time printing =
it=20
to the system console. It is in a simple for loop. When the program is=20
running press in quick succession the mouse about 10 to 20 times, The =
GUI=20
will hang, however the System console is still being updated.

Is this a bug, or is their another way to do this.

I would be most gratefull for any assistance.

Thanks

Matt

Sample program

public class Temp {

public static void main(String[] args) {
Temp t =3D new Temp();
t.start();
}
public void start(){
Display display =3D new Display();
Shell shell =3D new Shell(display);
Text text =3D new Text(shell,SWT.MULTI);
text.setSize(200,200);
text.setEditable(false);
shell.open();

int y=3D1000000;
for (int x=3D0;x<y;x++){
text.append("\nCounter.. "+x);
System.out.print("\nCounter.. "+x);
}

shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch())display.sleep();
}
display.dispose();
}
}

--____LPHMXLZMXOMRLFKSEJCW____
Content-Type: multipart/related; boundary="____WHPEPQYSAQXEHDGESJXG____"


--____WHPEPQYSAQXEHDGESJXG____
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3Diso-8859-1"=
>
<META content=3D"MSHTML 6.00.2900.2180" name=3DGENERATOR></HEAD>
<BODY style=3D"MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Hi Mani</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks for the tips.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I will give to try.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks</DIV>
<DIV>&nbsp;</DIV>
<DIV>Matt</DIV>
<DIV><BR>&gt;&gt;&gt; Mani Ghamari&lt;mani.ghamari@linkast.com&gt; =
12/12/2004 17:39:32 &gt;&gt;&gt;<BR></DIV>
<DIV style=3D"COLOR: #000000">Hi Matt,<BR><BR>Your "for" loop is a =
long-running process.<BR><BR>When you start clicking around while the loop =
is running, the mouse events <BR>are queued directly in the SWT event =
queue, which must be processed by the <BR>UI-Thread BEFORE any other GUI =
operations can be processed (e.g. <BR>Text.append(String str) ).<BR><BR>So,=
the mouse events block the event queue, because the the event processing =
<BR>code<BR>(generally:&nbsp; display.readAndDispatch()&nbsp; never gets a =
chance to process and <BR>execute (or in SWT terms, read and dispatch!) =
the queued events. (because <BR>the programm just "STAYS" in your for =
loop, the whole time).<BR><BR>Here is a possible solution to the problem =
which I use often myself: I put <BR>the update loop in a seperate Thread, =
so that the UI-Thread can process the <BR>events without getting blocked. =
Note that display.syncExec() is used to pass <BR>the UI-changing instructio=
ns back to the UI-Thread...<BR><BR>For more info, take a look at the API =
docs for:<BR>org.eclipse.swt.widgets.Display<BR>&amp;<BR >Display.syncExec(R=
unnable runnable)<BR>Display.asyncExec(Runnable runnable)<BR><BR>you might =
also want to take a look at the articles found on these pages, <BR>which =
both contain excellent tutorials for starters...:<BR><A href=3D"http://www.=
eclipse.org/articles">http://www.eclipse.org/articles</A><BR><A href=3D"htt=
p://www.cs.umanitoba.ca/~eclipse/">http://www.cs.umanitoba.ca/~eclipse/</A>=
<BR><BR>/* ***************** here is code********* */<BR><BR>import =
org.eclipse.swt.widgets.*;<BR>import org.eclipse.swt.*;<BR><BR>public =
class Temp implements Runnable<BR>{<BR>&nbsp;&nbsp;&nbsp; // display and =
text are made global so that the references are available <BR>within the =
run() method<BR>&nbsp;&nbsp;&nbsp; Display display;<BR>&nbsp;&nbsp;&nbsp; =
Text text;<BR><BR>&nbsp;&nbsp;&nbsp; // running is made global because =
otherwise it has to be declared final <BR>to be accessible<BR>&nbsp;&nbsp;&=
nbsp; // from the inner class<BR>&nbsp;&nbsp;&nbsp; boolean running;<BR><BR=
>&nbsp;&nbsp;&nbsp; public void run()<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int y=3D1000000;<BR><BR>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp; // if running is false, the shell is disposed and =
the thread should <BR>stop running<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp; // the variable running is used to prevent an Text.append(String =
<BR>str), after the text is<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
// disposed (otherwise .append() would throw a <BR>WidgetDisposedException)=
<BR><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; for (int x=3D0;x&lt;y =
&amp;&amp; running;x++)<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
{<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
final int x2 =3D x;<BR><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; // All calls to the GUI must be made within the =
UI-thread<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; display.syncExec(new Runnable()<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; public void run()<BR>&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbs=
p;&nbsp;&nbsp; {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp; if (!text.isDis=
posed())<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp; // shell and text are still =
there: update<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&=
nbsp; text.append("\nCounter.. "+x2);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.print("\nCounter.. "+x2);<BR>&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&n=
bsp; else<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp; // shell and text are =
disposed: stop running...<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&=
nbsp;&nbsp;&nbsp; running =3D false;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&n=
bsp; }<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; }<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp; });<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
}<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; public static void =
main(String[] args)<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; Temp t =3D new Temp();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; t.start();<BR>&nbsp;&nbsp;&nbsp; }<BR><BR>&nbsp;&nbsp;&nbsp; =
public void start()<BR>&nbsp;&nbsp;&nbsp; {<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; running =3D true;<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp; display =3D new Display();<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp; Shell shell =3D new Shell(display);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp; text =3D new Text(shell,SWT.MULTI);<BR>&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp; text.setSize(200,200);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp; text.setEditable(false);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; shell.open();<BR><BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
// shell is created, start the update thread...<BR>&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp; Thread thread =3D new Thread(this);<BR>&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp; thread.start();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp; // you dont need to open the shell twice...<BR>//&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; shell.open();<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp; while (!shell.isDisposed())<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp; {<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; if (!display.readAndDispatch())display.sleep();<BR>&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp; }<BR> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; =
display.dispose();<BR>&nbsp;&nbsp;&nbsp; }<BR>}<BR><BR><BR>regards,<BR><BR>=
Mani<BR><BR>"Matt McKenzie" &lt;mmckenzie@novell.com&gt; wrote in message =
<BR>news:cphqhm$nt5$1@<A href=3D"http://www.eclipse.org...">www.eclipse.org=
....</A><BR>Hi<BR><BR>I am new to java programing and even newer to SWT =
programming. I have found <BR>a problem where the GUI interface will =
"Hang". The background processes are <BR>all working but the GUI stops =
updating. (Running in a Windows XP <BR>environment)<BR><BR>I do not know =
if this is bug or a problem with my code. Below is a sample <BR>program =
that demonstrates the problem.<BR><BR>The program outputs a number to a =
text box and at the same time printing it <BR>to the system console. It is =
in a simple for loop. When the program is <BR>running press in quick =
succession the mouse about 10 to 20 times, The GUI <BR>will hang, however =
the System console is still being updated.<BR><BR>Is this a bug, or is =
their another way to do this.<BR><BR>I would be most gratefull for any =
assistance.<BR><BR>Thanks<BR><BR>Matt<BR><BR>Sample program<BR><BR>public =
class Temp {<BR><BR>public static void main(String[] args) {<BR>&nbsp; =
Temp t =3D new Temp();<BR>&nbsp; t.start();<BR>}<BR>public void start(){<BR=
>&nbsp; Display display =3D new Display();<BR>&nbsp; Shell shell =3D new =
Shell(display);<BR>&nbsp; Text text =3D new Text(shell,SWT.MULTI);<BR>&nbsp=
; text.setSize(200,200);<BR>&nbsp; text.setEditable(false);<BR>&nbsp; =
shell.open();<BR><BR>&nbsp; int y=3D1000000;<BR>&nbsp; for (int x=3D0;x&lt;=
y;x++){<BR>&nbsp;&nbsp; text.append("\nCounter..&nbsp; "+x);<BR>&nbsp;&nbsp=
; System.out.print("\nCounter..&nbsp; "+x);<BR>&nbsp; }<BR><BR>&nbsp; =
shell.open();<BR>&nbsp; while (!shell.isDisposed()){<BR>&nbsp;&nbsp; if =
(!display.readAndDispatch())display.sleep();<BR>&nbsp; }<BR>&nbsp; =
display.dispose();<BR>}<BR>} <BR><BR><BR><BR><BR></DIV></BODY></HTML>

--____WHPEPQYSAQXEHDGESJXG____--

--____LPHMXLZMXOMRLFKSEJCW____--
Previous Topic:SWT: Stand alone jar
Next Topic:ATT: Ms. Irvine - Bug in Eclipse Article: DND
Goto Forum:
  


Current Time: Sat Oct 24 21:31:28 GMT 2020

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

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

Back to the top