Re: Alternative for Thread.sleep()
From: ak (spam_at_imagero.com)
Date: 05/22/04
- Previous message: Roedy Green: "Re: table does not show until resizing"
- In reply to: Frederik: "Alternative for Thread.sleep()"
- Next in thread: Frederik: "Re: Alternative for Thread.sleep()"
- Reply: Frederik: "Re: Alternative for Thread.sleep()"
- Reply: Antti S. Brax: "Re: Alternative for Thread.sleep()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 22 May 2004 19:32:26 +0200
> I'm having a JProgressbar in a JDialog. For visual purposes, I need to
> slow down the progress in the JProgressbar. For that I use:
>
> // in a new thread
> objProgBar.setValue(objProgBar.getValue() + 1);
> try { Thread.sleep(1); }
> catch (Exception e) {}
>
> But this is too slow!!!
>
> On the other hand, when I replace the "try catch" block above with
> something like "int i=0; i++;" it is too fast. What can I do to get
> the speed I need (which is something in between)?
the simpliest way is to call Thread.sleep not every time when you call
setValue:
int value = objProgBar.getValue();
objProgBar.setValue(value + 1);
if(value % 5 == 0) {
try { Thread.sleep(1); }
catch (Exception e) {}
}
-- http://uio.dev.java.net http://reader.imagero.com
- Previous message: Roedy Green: "Re: table does not show until resizing"
- In reply to: Frederik: "Alternative for Thread.sleep()"
- Next in thread: Frederik: "Re: Alternative for Thread.sleep()"
- Reply: Frederik: "Re: Alternative for Thread.sleep()"
- Reply: Antti S. Brax: "Re: Alternative for Thread.sleep()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|