Results 1 to 5 of 5
  1. #1
    Jozo is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default setText() problem

    Hi all!
    I have a problem - my Java program doesn't do what I want to. He doesn't display "downloading effect" - he waits 5 seconds and then sets text: 100% downloaded. Please help!

    for(int i=0;i<101;i++)
    {
    t1.setText(i + "% downloaded...");
    try {Thread.currentThread().sleep(50);}
    catch (InterruptedException a) {
    a.printStackTrace();
    }}

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    If you call Thread.sleep in the main GUI thread (the EDT), you in effect put the whole app to sleep. If this is a Swing app, you're far better off using a Swing Timer.

  3. #3
    Jozo is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default

    OK
    can you change my code that it works?
    thanks

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by Jozo View Post
    OK
    can you change my code that it works?
    thanks
    It would be much better if you read the tutorial and did it yourself: How to Use Swing Timers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features) as you would learn much more in the process. Please feel free to come on back if it doesn't work, and much luck!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Jozo View Post
    OK
    can you change my code that it works?
    thanks
    You should know how to do this. If not I think it's better to study about Java basis and related I think. Or at least as Fubarable says try to read a related article/tutorial and give a try.

Similar Threads

  1. setText in JTextArea
    By hero in forum AWT / Swing
    Replies: 1
    Last Post: 10-12-2009, 09:38 PM
  2. Replies: 3
    Last Post: 05-25-2009, 03:33 AM
  3. setText() problem
    By jls7168 in forum New To Java
    Replies: 2
    Last Post: 02-20-2009, 10:34 PM
  4. [SOLVED] new2java- gettext settext
    By obdi in forum New To Java
    Replies: 4
    Last Post: 07-21-2008, 09:28 AM
  5. setText in event
    By sniezna.stopa in forum SWT / JFace
    Replies: 0
    Last Post: 06-20-2008, 02:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •