Results 1 to 9 of 9
  1. #1
    jnaevwa is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default JProgressBar with Input

    does any one know if there is any why to set a JProgressBar to sense how far or weather a file/audio is imputed

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default

    Would you want to display the % of the total number of bytes that are to be read?
    With a file you know how many bytes the file has and how many you have read.
    I have no idea about audio.

  3. #3
    jnaevwa is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    % of the total is what I would be looking for and audio is just like files in the case I am talking about
    Last edited by jnaevwa; 07-04-2011 at 04:53 AM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default

    % = bytes read / total bytes * 100

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    And don't fall in the trap of integer division: use doubles.

    db

  6. #6
    jnaevwa is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    the only way I have found to get the # of bytes in a file(java.io.File length method) returns a long value should I cast it to a double? also I can not find a way to sense how many bytes have been reAd I know its alittle of the main topic buy if you know how please could you tell me
    Last edited by jnaevwa; 07-04-2011 at 07:49 PM.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default

    how many bytes have been reAd
    Depends on what method you are using to read with.
    For each read you do, there will be a way to determine how many bytes were read. Sum those amounts up to get the total bytes read so far.

  8. #8
    jnaevwa is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    I know I am getting far off topic but the most easy way to sense how many bytes have been read is the mark method of the InputStream class(that is if I understand it correctly)

    the javadoc of the method is below

    mark

    public void mark(int readlimit)

    Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

    The readlimit arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.

    The general contract of mark is that, if the method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called.

  9. #9
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by jnaevwa View Post
    I know I am getting far off topic but the most easy way to sense how many bytes have been read is the mark method of the InputStream class(that is if I understand it correctly)
    How it the mark method going to tell you how many bytes were read? it doesn't return a value...

    Why not try the advice you asked for and were kindly given by Norm?

Similar Threads

  1. Updating JProgressBar
    By suraj.routh in forum AWT / Swing
    Replies: 1
    Last Post: 06-04-2011, 02:57 AM
  2. JProgressBar and SQL query
    By telecomVic in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-17-2011, 02:40 PM
  3. i try to put JProgressBar i jtabl
    By yontan8888 in forum AWT / Swing
    Replies: 2
    Last Post: 03-01-2011, 08:19 AM
  4. Problem With JProgressBar
    By akssingh400 in forum AWT / Swing
    Replies: 6
    Last Post: 02-24-2011, 07:08 PM
  5. JprogressBar
    By cotarelo in forum AWT / Swing
    Replies: 7
    Last Post: 03-26-2010, 04:13 AM

Posting Permissions

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