got a problem with jtextfiled..

  • Follow


let's say....i have a jtextfiled ....

JTextField txtNo = new JTextField();

for( int i =0; i<100000; i++){
     //Thread.sleep(100);
     txtNo.setText(i+"");

}


when i'm running it....i want to see the number increasing...but all i
see is...the last result of 99999

it just hangs a while and suddenly appears the last number only...

i want to see flicking..is there anyway????

thanks for reading....
0
Reply jlc488 (9) 11/25/2007 4:34:41 AM

On Nov 25, 1:34 pm, jlc488 <jlc...@gmail.com> wrote:
> let's say....i have a jtextfiled ....
>
> JTextField txtNo = new JTextField();
>
> for( int i =0; i<100000; i++){
>      //Thread.sleep(100);
>      txtNo.setText(i+"");
>
> }
>
> when i'm running it....i want to see the number increasing...but all i
> see is...the last result of 99999
>
> it just hangs a while and suddenly appears the last number only...
>
> i want to see flicking..is there anyway????
>
> thanks for reading....

See http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
Swing runs in a single thread in which you do a long task that
prevents Swing to run.
0
Reply hiwa 11/25/2007 5:05:20 AM


hiwa wrote:
> On Nov 25, 1:34 pm, jlc488 <jlc...@gmail.com> wrote:
>> let's say....i have a jtextfiled ....
>>
>> JTextField txtNo = new JTextField();
>>
>> for( int i =0; i<100000; i++){
>>      //Thread.sleep(100);
>>      txtNo.setText(i+"");
>>
>> }
>>
>> when i'm running it....i want to see the number increasing...but all i
>> see is...the last result of 99999
>>
>> it just hangs a while and suddenly appears the last number only...
>>
>> i want to see flicking..is there anyway????
>>
>> thanks for reading....
> 
> See http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
> Swing runs in a single thread

called the "Event Dispatch Thread", or EDT,

> in which you do a long task that prevents Swing to run.

And if you apply changes from a different thread it might not update visibly 
in the EDT.  The link hiwa gave will give you a beginning.

<http://mindprod.com/jgloss/swing.html>
is another good source of information.

-- 
Lew
0
Reply Lew 11/25/2007 5:31:27 AM

On 11=BF=F925=C0=CF, =BF=C0=C8=C42=BD=C331=BA=D0, Lew <l...@lewscanon.com> w=
rote:
> hiwa wrote:
> > On Nov 25, 1:34 pm, jlc488 <jlc...@gmail.com> wrote:
> >> let's say....i have a jtextfiled ....
>
> >> JTextField txtNo =3D new JTextField();
>
> >> for( int i =3D0; i<100000; i++){
> >>      //Thread.sleep(100);
> >>      txtNo.setText(i+"");
>
> >> }
>
> >> when i'm running it....i want to see the number increasing...but all i
> >> see is...the last result of 99999
>
> >> it just hangs a while and suddenly appears the last number only...
>
> >> i want to see flicking..is there anyway????
>
> >> thanks for reading....
>
> > Seehttp://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.htm=
l
> > Swing runs in a single thread
>
> called the "Event Dispatch Thread", or EDT,
>
> > in which you do a long task that prevents Swing to run.
>
> And if you apply changes from a different thread it might not update visib=
ly
> in the EDT.  The link hiwa gave will give you a beginning.
>
> <http://mindprod.com/jgloss/swing.html>
> is another good source of information.
>
> --
> Lew- =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BC=FB=B1=E2=B1=E2 -
>
> - =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BA=B8=B1=E2 -

i'm not quite understanding..with edt...

i've tried with AWT...this setText is good....

it shows what i want to see...but why not in Swing??

and is there any sample code you can show to me??

thanks..a lot
0
Reply jlc488 11/25/2007 7:23:21 AM

On Nov 25, 4:23 pm, jlc488 <jlc...@gmail.com> wrote:
> On 11=BF=F925=C0=CF, =BF=C0=C8=C42=BD=C331=BA=D0, Lew <l...@lewscanon.com>=
 wrote:
>
>
>
> > hiwa wrote:
> > > On Nov 25, 1:34 pm, jlc488 <jlc...@gmail.com> wrote:
> > >> let's say....i have a jtextfiled ....
>
> > >> JTextField txtNo =3D new JTextField();
>
> > >> for( int i =3D0; i<100000; i++){
> > >>      //Thread.sleep(100);
> > >>      txtNo.setText(i+"");
>
> > >> }
>
> > >> when i'm running it....i want to see the number increasing...but all =
i
> > >> see is...the last result of 99999
>
> > >> it just hangs a while and suddenly appears the last number only...
>
> > >> i want to see flicking..is there anyway????
>
> > >> thanks for reading....
>
> > > Seehttp://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.h=
tml
> > > Swing runs in a single thread
>
> > called the "Event Dispatch Thread", or EDT,
>
> > > in which you do a long task that prevents Swing to run.
>
> > And if you apply changes from a different thread it might not update vis=
ibly
> > in the EDT.  The link hiwa gave will give you a beginning.
>
> > <http://mindprod.com/jgloss/swing.html>
> > is another good source of information.
>
> > --
> > Lew- =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BC=FB=B1=E2=B1=E2 -
>
> > - =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BA=B8=B1=E2 -
>
> i'm not quite understanding..with edt...
>
> i've tried with AWT...this setText is good....
>
> it shows what i want to see...but why not in Swing??
>
> and is there any sample code you can show to me??
>
> thanks..a lot

Wa, wa, wa, wait! Some of JTextComponent methods are thread safe. Your
original code should run normally as is. Try this:
------------------------------------------
import java.awt.*;
import javax.swing.*;

public class SwingTf{

  public static void main(String[] args) throws Exception{

    JFrame frame =3D new JFrame();
    JTextField tf =3D new JTextField(30);
    frame.getContentPane().add(tf, BorderLayout.SOUTH);
    frame.pack();
    frame.setVisible(true);

    for( int i =3D0; i<100000; i++){
//     Thread.sleep(100);
     tf.setText(i + "");
    }
  }
}
------------------------------------------
0
Reply hiwa 11/25/2007 10:16:30 AM

hiwa wrote:
>> > >> let's say....i have a jtextfiled ....
...
>Wa, wa, wa, wait! Some of JTextComponent methods are thread safe. Your
>original code should run normally as is. Try this:

Good point.  OTOH, I think this problem *might* be
better suited to a progress bar (which would require
accounting for the 'update on EDT').  Try doing this 
using AWT!

<sscce>
import java.awt.BorderLayout;
import javax.swing.*;

public class SwingProgress {

 public static void main(String[] args) throws Exception {

   JFrame frame = new JFrame();
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   int num = 1000;
   JProgressBar pb = new JProgressBar(0,num);
   pb.setStringPainted(true);
   frame.getContentPane().add(pb, BorderLayout.CENTER);
   frame.pack();
   frame.setVisible(true);

   for( int i =0; i<=num; i++){
     Thread.sleep(5);
	 pb.setValue(i);
   }
   System.out.println("Finished");
 }
}
</sscce>

-- 
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200711/1

0
Reply Andrew 11/25/2007 11:01:26 AM

On 11=BF=F925=C0=CF, =BF=C0=C8=C48=BD=C301=BA=D0, "Andrew Thompson" <u32984@=
uwe> wrote:
> hiwa wrote:
> >> > >> let's say....i have a jtextfiled ....
> ..
> >Wa, wa, wa, wait! Some of JTextComponent methods are thread safe. Your
> >original code should run normally as is. Try this:
>
> Good point.  OTOH, I think this problem *might* be
> better suited to a progress bar (which would require
> accounting for the 'update on EDT').  Try doing this
> using AWT!
>
> <sscce>
> import java.awt.BorderLayout;
> import javax.swing.*;
>
> public class SwingProgress {
>
>  public static void main(String[] args) throws Exception {
>
>    JFrame frame =3D new JFrame();
>    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>    int num =3D 1000;
>    JProgressBar pb =3D new JProgressBar(0,num);
>    pb.setStringPainted(true);
>    frame.getContentPane().add(pb, BorderLayout.CENTER);
>    frame.pack();
>    frame.setVisible(true);
>
>    for( int i =3D0; i<=3Dnum; i++){
>      Thread.sleep(5);
>          pb.setValue(i);
>    }
>    System.out.println("Finished");
>  }}
>
> </sscce>
>
> --
> Andrew Thompsonhttp://www.physci.org/
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-se=
tup/200711/1



ok...if i run above codes inside the main function...then it would be
fine....but..the..problem is...

i'm running this...using Jbutton....

when i click the button...this will trigger the job....

so they are like this....

private void btnStartActionPerformed(java.awt.event.ActionEvent evt)
{
     this.gogo();
}

private void gogo(){
   try{
       for (int i =3D 0; i < 100000; i++) {
           this.txtNo.setText(i+""); <-- swing.JTextField
           this.txtTest.setText(i+"");  <-- this one is awt.TextField
           this.progressBar.setValue(i); <-- swing.JprogressBar
           System.out.println(i);
       }
   }catch(Exception e ){}
}

the code is like above..and the class extends JFrame.....

i was using netbean 5.5.1 to desing the UI...and somehow....txtTest
field using awt..only shows the numbers running...and...other..swing
components..are only showing the last number only...i mean like you
said hiwa...if i'm running it inside the main funciton ...

it does not have anyproblem...do you have any idea what's wrong with
this???

thanks guys...
0
Reply jlc488 11/25/2007 12:03:56 PM

>"jlc488" <jlc488@gmail.com> wrote in message 
>news:ffb725af-fc16-4bd5-8923-338ac70aeaa3@d27g2000prf.googlegroups.com...
>On 11��25��, ����8��01��, "Andrew Thompson" <u32984@uwe> wrote:
>> hiwa wrote:
>> >> > >> let's say....i have a jtextfiled ....
>> ..
>> >Wa, wa, wa, wait! Some of JTextComponent methods are thread safe. Your
>> >original code should run normally as is. Try this:
>>
>> Good point.  OTOH, I think this problem *might* be
>> better suited to a progress bar (which would require
>> accounting for the 'update on EDT').  Try doing this
>> using AWT!
>>
>> <sscce>
>> import java.awt.BorderLayout;
>> import javax.swing.*;
>>
>> public class SwingProgress {
>>
>>  public static void main(String[] args) throws Exception {
>>
>>    JFrame frame = new JFrame();
>>    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
>>    int num = 1000;
>>    JProgressBar pb = new JProgressBar(0,num);
>>    pb.setStringPainted(true);
>>    frame.getContentPane().add(pb, BorderLayout.CENTER);
>>    frame.pack();
>>    frame.setVisible(true);
>>
>>    for( int i =0; i<=num; i++){
>>      Thread.sleep(5);
>>          pb.setValue(i);
>>    }
>>    System.out.println("Finished");
>>  }}
>>
>> </sscce>
>>
>> --
>> Andrew Thompsonhttp://www.physci.org/
>>
>> Message posted via 
>> JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-setup/200711/1
>
>
>
>
>ok...if i run above codes inside the main function...then it would be
>fine....but..the..problem is...
>
>i'm running this...using Jbutton....
>
>when i click the button...this will trigger the job....
>
>so they are like this....
>
>private void btnStartActionPerformed(java.awt.event.ActionEvent evt)
>{
>     this.gogo();
>}
>
>private void gogo(){
>   try{
>       for (int i = 0; i < 100000; i++) {
>           this.txtNo.setText(i+""); <-- swing.JTextField
>           this.txtTest.setText(i+"");  <-- this one is awt.TextField
>           this.progressBar.setValue(i); <-- swing.JprogressBar
>           System.out.println(i);
>       }
>   }catch(Exception e ){}
>}
>
>the code is like above..and the class extends JFrame.....
>
>i was using netbean 5.5.1 to desing the UI...and somehow....txtTest
>field using awt..only shows the numbers running...and...other..swing
>components..are only showing the last number only...i mean like you
>said hiwa...if i'm running it inside the main funciton ...
>
>it does not have anyproblem...do you have any idea what's wrong with
>this???
>
>thanks guys...

Being threadsafe simply means that setText can be called from another 
thread--your loop is still blocking the EDT.  Andrew's version works because 
the main thread is not the EDT whereas "gogo" is invoked on the EDT, 
blocking it until the loop ends.  For GUI updates to be visible while they 
are in progress they must be activated from a different thread so that the 
EDT can keep up the job of updating the screen.

Matt Humphrey http://www.iviz.com/ 


0
Reply Matt 11/25/2007 12:51:48 PM

On 11=EC=9B=9425=EC=9D=BC, =EC=98=A4=ED=9B=849=EC=8B=9C51=EB=B6=84, "Matt Hu=
mphrey" <ma...@iviz.com> wrote:
> >"jlc488" <jlc...@gmail.com> wrote in message
> >news:ffb725af-fc16-4bd5-8923-338ac70aeaa3@d27g2000prf.googlegroups.com...=

> >On 11=C2=BF=C3=B925=C3=80=C3=8F, =C2=BF=C3=80=C3=88=C3=848=C2=BD=C3=8301=
=C2=BA=C3=90, "Andrew Thompson" <u32984@uwe> wrote:
> >> hiwa wrote:
> >> >> > >> let's say....i have a jtextfiled ....
> >> ..
> >> >Wa, wa, wa, wait! Some of JTextComponent methods are thread safe. Your=

> >> >original code should run normally as is. Try this:
>
> >> Good point. =C2=A0OTOH, I think this problem *might* be
> >> better suited to a progress bar (which would require
> >> accounting for the 'update on EDT'). =C2=A0Try doing this
> >> using AWT!
>
> >> <sscce>
> >> import java.awt.BorderLayout;
> >> import javax.swing.*;
>
> >> public class SwingProgress {
>
> >> =C2=A0public static void main(String[] args) throws Exception {
>
> >> =C2=A0 =C2=A0JFrame frame =3D new JFrame();
> >> =C2=A0 =C2=A0frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> >> =C2=A0 =C2=A0int num =3D 1000;
> >> =C2=A0 =C2=A0JProgressBar pb =3D new JProgressBar(0,num);
> >> =C2=A0 =C2=A0pb.setStringPainted(true);
> >> =C2=A0 =C2=A0frame.getContentPane().add(pb, BorderLayout.CENTER);
> >> =C2=A0 =C2=A0frame.pack();
> >> =C2=A0 =C2=A0frame.setVisible(true);
>
> >> =C2=A0 =C2=A0for( int i =3D0; i<=3Dnum; i++){
> >> =C2=A0 =C2=A0 =C2=A0Thread.sleep(5);
> >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pb.setValue(i);
> >> =C2=A0 =C2=A0}
> >> =C2=A0 =C2=A0System.out.println("Finished");
> >> =C2=A0}}
>
> >> </sscce>
>
> >> --
> >> Andrew Thompsonhttp://www.physci.org/
>
> >> Message posted via
> >> JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-setup/200711/1
>
> >ok...if i run above codes inside the main function...then it would be
> >fine....but..the..problem is...
>
> >i'm running this...using Jbutton....
>
> >when i click the button...this will trigger the job....
>
> >so they are like this....
>
> >private void btnStartActionPerformed(java.awt.event.ActionEvent evt)
> >{
> > =C2=A0 =C2=A0 this.gogo();
> >}
>
> >private void gogo(){
> > =C2=A0 try{
> > =C2=A0 =C2=A0 =C2=A0 for (int i =3D 0; i < 100000; i++) {
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this.txtNo.setText(i+""); <-- swing.J=
TextField
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this.txtTest.setText(i+""); =C2=A0<--=
 this one is awt.TextField
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 this.progressBar.setValue(i); <-- swi=
ng.JprogressBar
> > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.println(i);
> > =C2=A0 =C2=A0 =C2=A0 }
> > =C2=A0 }catch(Exception e ){}
> >}
>
> >the code is like above..and the class extends JFrame.....
>
> >i was using netbean 5.5.1 to desing the UI...and somehow....txtTest
> >field using awt..only shows the numbers running...and...other..swing
> >components..are only showing the last number only...i mean like you
> >said hiwa...if i'm running it inside the main funciton ...
>
> >it does not have anyproblem...do you have any idea what's wrong with
> >this???
>
> >thanks guys...
>
> Being threadsafe simply means that setText can be called from another
> thread--your loop is still blocking the EDT. =C2=A0Andrew's version works =
because
> the main thread is not the EDT whereas "gogo" is invoked on the EDT,
> blocking it until the loop ends. =C2=A0For GUI updates to be visible while=
 they
> are in progress they must be activated from a different thread so that the=

> EDT can keep up the job of updating the screen.
>
> Matt Humphreyhttp://www.iviz.com/- =EB=94=B0=EC=98=A8 =ED=85=8D=EC=8A=A4=
=ED=8A=B8 =EC=88=A8=EA=B8=B0=EA=B8=B0 -
>
> - =EB=94=B0=EC=98=A8 =ED=85=8D=EC=8A=A4=ED=8A=B8 =EB=B3=B4=EA=B8=B0 -

oh...ok...if it is that case what should i do ??

any suggestions?? matt??
0
Reply jlc488 11/25/2007 1:44:35 PM

jlc488 wrote:
>> >> >> > >> let's say....i have a jtextfiled ....
>> >> ..
>[quoted text clipped - 85 lines]

Please trim text no longer immediately relevant to a reply.
(There was no need to quote 85+ lines of earlier conversation,
just to ask your question.
...
>oh...ok...if it is that case what should i do ??

You might get some pointers from *this* JProgressBar demo.
<http://java.sun.com/docs/books/tutorial/uiswing/examples/components/ProgressBarDemoProject/src/components/ProgressBarDemo.java
>

>any suggestions?? 

Sure.
- Post SSCCEs*, rather than code snippets.
- Spell J2SE classes with correct capitalisation, to indicate
that they are J2SE classes, rather than some 3rd party 
equivalent.  On this note, it is JTextField and JButton, 
as opposed to 'jtextfiled' and 'Jbutton'.
- Start each sentence with a single Capital Letter.
- Always capitalise the word 'I'.
- Add a single full-stop '.' at the end of each sentence, and
2 spaces before start of the next.
- Note that one single '?' is enough to indicate a question.

* <http://www.physci.org/codes/sscce.html>
<http://homepage1.nifty.com/algafield/sscce.html>

-- 
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200711/1

0
Reply Andrew 11/25/2007 4:49:50 PM

Andrew Thompson wrote:
> * <http://www.physci.org/codes/sscce.html>

Still shows litter:
> <%@ include file = "/codes/all_inc/pageInfo.f.html" %>
in the upper right-hand corner, and
> <%@ include file = "/all_inc/call_google_js.f.html" %> 
in the upper-left, under the "Find" button.

> <http://homepage1.nifty.com/algafield/sscce.html>

Clean and vivid.  Is that yours, or a mirror?

-- 
Lew
0
Reply Lew 11/25/2007 6:42:10 PM

> "jlc488" <jlc488@gmail.com> wrote in message 
> news:ccf4ff34-ec32-41bc-aace-46bcf6246c1b@b40g2000prf.googlegroups.com...
> On 11?25?, ??9?51?, "Matt Humphrey" <ma...@iviz.com> wrote:

> > Being threadsafe simply means that setText can be called from another
> > thread--your loop is still blocking the EDT. Andrew's version works 
> > because
> > the main thread is not the EDT whereas "gogo" is invoked on the EDT,
> > blocking it until the loop ends. For GUI updates to be visible while 
> > they
> > are in progress they must be activated from a different thread so that 
> > the
> > EDT can keep up the job of updating the screen.
> >
> > Matt Humphreyhttp://www.iviz.com/- ?? ??? ??? -
> >
> > - ?? ??? ?? -
>
> oh...ok...if it is that case what should i do ??
>
> any suggestions?? matt??

You have to perform the action in a separate thread, like in the following 
example.

private void gogo(){
  Thread t = new Thread (new Runnable () {
     public void run () {
        try{
           for (int i = 0; i < 100000; i++) {
               this.txtNo.setText(i+"");
           }
       }catch(Exception e ){ e.printStackTrace (); }
  });
  t.start ();
}


This works only for threadsafe methods like setText.  Virtually everything 
else (except repaint) is not threadsafe and you must perform the actual 
update in the EDT.  (Confusing, yes?  Time-consuming task code must NOT be 
in EDT, update code MUST be in EDT). The example provided by Andrew shows 
how to use SwingWorker to setup a thread to do the working off the EDT and 
it manages to do the done method in the EDT.  Also, that example shows the 
correct way to launch a GUI in the EDT rather than in the main thread.

http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html

Matt Humphrey http://www.iviz.com/ 


0
Reply Matt 11/25/2007 8:05:31 PM

Lew wrote:
>> * <http://www.physci.org/codes/sscce.html>
>
>Still shows litter:

Will probably have a better version to upload within 24-48 hours.

>> <http://homepage1.nifty.com/algafield/sscce.html>
>
>Clean and vivid.  Is that yours, or a mirror?

That is hiwa's mirror (for which I am very grateful, given
it has been significantly more accessible than my own
copy).

-- 
Andrew Thompson
http://www.physci.org/

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-setup/200711/1

0
Reply Andrew 11/26/2007 1:58:56 AM

jlc488 wrote:
> Matt Humphrey wrote:
>> Being threadsafe simply means that setText can be called from another
>> thread--your loop is still blocking the EDT.  Andrew's version works because
>> the main thread is not the EDT whereas "gogo" is invoked on the EDT,
>> blocking it until the loop ends.  For GUI updates to be visible while they
>> are in progress they must be activated from a different thread so that the
>> EDT can keep up the job of updating the screen.
>>
> 
> oh...ok...if it is that case what should i do ??
> 
> any suggestions?? 

After I thought I understood threading and the dependence of most of 
Swing on the Event Dispatch Thread, I found it helpful to read about 
Thread.start(), SwingUtilities.invokeLater() and SwingWorker.

Something that I am currently finding useful is the code at
http://www.clientjava.com/blog/2004/08/20/1093059428000.html

After including that in my project I just insert
RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager());
at the beginning of my program. It seems quite good at telling me when 
I've made a mistake in running Swing code from the "wrong" thread.

0
Reply RedGrittyBrick 11/26/2007 2:42:07 PM

On 11=BF=F926=C0=CF, =BF=C0=C0=FC5=BD=C305=BA=D0, "Matt Humphrey" <ma...@ivi=
z.com> wrote:
> > "jlc488" <jlc...@gmail.com> wrote in message
> >news:ccf4ff34-ec32-41bc-aace-46bcf6246c1b@b40g2000prf.googlegroups.com...=

> > On 11?25?, ??9?51?, "Matt Humphrey" <ma...@iviz.com> wrote:
> > > Being threadsafe simply means that setText can be called from another
> > > thread--your loop is still blocking the EDT. Andrew's version works
> > > because
> > > the main thread is not the EDT whereas "gogo" is invoked on the EDT,
> > > blocking it until the loop ends. For GUI updates to be visible while
> > > they
> > > are in progress they must be activated from a different thread so that=

> > > the
> > > EDT can keep up the job of updating the screen.
>
> > > Matt Humphreyhttp://www.iviz.com/-?? ??? ??? -
>
> > > - ?? ??? ?? -
>
> > oh...ok...if it is that case what should i do ??
>
> > any suggestions?? matt??
>
> You have to perform the action in a separate thread, like in the following=

> example.
>
> private void gogo(){
>   Thread t =3D new Thread (new Runnable () {
>      public void run () {
>         try{
>            for (int i =3D 0; i < 100000; i++) {
>                this.txtNo.setText(i+"");
>            }
>        }catch(Exception e ){ e.printStackTrace (); }
>   });
>   t.start ();
>
> }
>
> This works only for threadsafe methods like setText.  Virtually everything=

> else (except repaint) is not threadsafe and you must perform the actual
> update in the EDT.  (Confusing, yes?  Time-consuming task code must NOT be=

> in EDT, update code MUST be in EDT). The example provided by Andrew shows
> how to use SwingWorker to setup a thread to do the working off the EDT and=

> it manages to do the done method in the EDT.  Also, that example shows the=

> correct way to launch a GUI in the EDT rather than in the main thread.
>
> http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html
>
> Matt Humphreyhttp://www.iviz.com/- =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BC=FB=
=B1=E2=B1=E2 -
>
> - =B5=FB=BF=C2 =C5=D8=BD=BA=C6=AE =BA=B8=B1=E2 -

thanks..it really helped me a lot...

thank  you matt..i really appreciated...bye~~
0
Reply jlc488 11/30/2007 1:41:14 AM

14 Replies
95 Views

(page loaded in 0.207 seconds)

Similiar Articles:


















7/11/2012 9:44:06 AM


Reply: