Results 1 to 9 of 9
  1. #1
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Arrow JProgress Bar - How to wait before the next .setValue() is called

    Hi there,

    Using a progress bar on the program loadup screen for my final school project.

    I've run into an issue however.

    How do I make the system wait before I update the progress bar?

    I've tried the .wait() method, inside a try catch but always get a run-time error.

    any suggestions?

    by the way: this is a 'fake' progress bar. The program it's self is a realitively small program and will use little system resources. i just wanted to add a little 'touch' for some pezazz.
    Last edited by Unsub; 04-07-2010 at 11:20 PM.

  2. #2
    newb_tewb is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default

    Use a thread.sleep( long ms)
    where ms = how long in milliseconds you want it to wait for

  3. #3
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    all that is doing is delaying the display of the entire screen until the specified ms has passed.


    i'm lookin to have it display everything within the frame and then delay the updating of just the progress bar

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

    Default

    Thread.sleep is a very bad idea as it will just put the EDT, the main thread that runs Swing -- and by doing this, your whole program -- to sleep. Perhaps you want to use either a Swing Timer (my preference) or a background timer.

  5. #5
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    Thread.sleep is a very bad idea as it will just put the EDT, the main thread that runs Swing -- and by doing this, your whole program -- to sleep. Perhaps you want to use either a Swing Timer (my preference) or a background timer.
    i'm a little confused with how these timers work, can you explain a little bit to me?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Unsub View Post
    i'm a little confused with how these timers work, can you explain a little bit to me?
    I could, but the Sun Tutorials do a much better job than anything I could do: How to use Swing Timers

  7. #7
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    I could, but the Sun Tutorials do a much better job than anything I could do: How to use Swing Timers
    timer = new Timer(speed, this);

    generates an error. Constructor not found to be persice.

    i've imported java.util.Timer;

    anythoughts?
    Last edited by Unsub; 04-08-2010 at 10:38 PM.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    There are two Timers that are commonly used, the java.util.Timer and the javax.swing.Timer. Since this is Swing, and you want your timer actions called on Swing's main event thread, use the javax.swing.Timer, or Swing Timer. Much luck!

  9. #9
    Unsub's Avatar
    Unsub is offline Member
    Join Date
    Jan 2010
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    There are two Timers that are commonly used, the java.util.Timer and the javax.swing.Timer. Since this is Swing, and you want your timer actions called on Swing's main event thread, use the javax.swing.Timer, or Swing Timer. Much luck!
    A million thanx!
    Rep++

Similar Threads

  1. Need help with wait() and notify()
    By Mkaveli in forum Threads and Synchronization
    Replies: 2
    Last Post: 03-30-2010, 12:58 PM
  2. update() gets never called
    By flok in forum AWT / Swing
    Replies: 8
    Last Post: 10-19-2009, 05:45 PM
  3. about wait() and notifyALL
    By denis in forum Threads and Synchronization
    Replies: 13
    Last Post: 04-22-2009, 09:28 AM
  4. Thread Wait
    By jiexx in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-19-2009, 06:26 PM
  5. How to use sleep() to wait for a while
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 07:32 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
  •