Re: Alternative for Thread.sleep()

From: ak (spam_at_imagero.com)
Date: 05/22/04

  • Next message: Abs: "Selecting items in a JList"
    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
    

  • Next message: Abs: "Selecting items in a JList"

    Relevant Pages

    • Alternative for Thread.sleep()
      ... I'm having a JProgressbar in a JDialog. ... For visual purposes, I need to ... slow down the progress in the JProgressbar. ...
      (comp.lang.java.gui)
    • JProgressBar .... need assistance please..
      ... I'm playing with the idea of showing a JProgressBar in a small App' I trying ... I want to display the progress of an array being populated....however I cant ... ActionListener act = new ActionListener{ ...
      (comp.lang.java.programmer)
    • JProgressBar... need assiatance please
      ... I'm playing with the idea of showing a JProgressBar in a small App' I trying ... I want to display the progress of an array being populated....however I cant ... ActionListener act = new ActionListener{ ...
      (comp.lang.java.help)
    • JProgressBar - Determinate Works, Indeterminate Does Not
      ... Below is my code for the TableCellRenderer (which is a JProgressBar). ... bar is updated to match the progress for that specifici process. ... * java.lang.Object, boolean, boolean, int, int) ...
      (comp.lang.java.gui)
    • progress bar with windows look and feel
      ... Using winMe with jdk1.4, and with default java look and feel, my application ... displayed in windows look and feel, however, my JProgressBar has a problem. ... It pops up but does not show progress, and then closes when the file has ... in java default laf but not in windows laf. ...
      (comp.lang.java.programmer)