Results 1 to 3 of 3
  1. #1
    innovo is offline Member
    Join Date
    Jul 2015
    Posts
    84
    Rep Power
    0

    Default can't get progress bar to count linearly?

    Hello all,

    Lately I've been trying to have a progressbar go forward every time I do a specific task in Java. In this case writing to a file. Thus every time I write to a file the progress bar will go up 1/40. I used to be able to count linearly when I had 2 textfields. However I recently had to remove one and tack on things to one texfield instead of 2.

    Textfield 1 was supposed to take in a number
    Textfield 2 was supposed to have a number which would be inputted and would loop Textfield 1 amount of times

    Since I had to remove Textfield 1 I have to both
    1) take in a number (if it's bigger thanTextfield2+1)
    2) loop that many times until I hit the number inputted

    While I have made Textbox 2 do what both textboxes used to do, the problem is I can't make the progressbar count linearly at all, or the number displayed in my UI(which is tied to the progress bar)
    Clearly I am doing something wrong here, but what?

    Java Code:
    private void writeOut(){
            double loops = Double.parseDouble(jTextField2.getText())+1;
           double currentItem = Double.parseDouble(jTextField2.getText());
           int currentitem= Integer.parseInt(jTextField2.getText())+1;
           int things;
            String newOut;
            things = ((currentitem)-1)/4;
        try {
            FileWriter outFile = new FileWriter(templateFile, true);
            BufferedWriter outWriter = new BufferedWriter(outFile);
            PrintWriter output = new PrintWriter(outWriter);
            
            while(loops > 0 && progress <= 40){
                newOut = compileOutput();
                
                output.append(newOut);
                
                //jTextField1.setText(String.valueOf(--loops).indexOf(".") < 0 ? String.valueOf(loops) : String.valueOf(loops).replaceAll("0*$", "").replaceAll("\\.$", ""));
              //  if(currentItem>1){
               // things= things+(things-things)+1;
               //   }
                
                loops =progress;
                progress=things;
               ++things;
                jTextField2.setText(String.valueOf(things).indexOf(".") < 0 ? String.valueOf(things) : String.valueOf(things).replaceAll("0*$", "").replaceAll("\\.$", ""));
                jProgressBar1.setValue(things);
                jProgressBar1.setString(things + "/40");
            }
            
            outWriter.close();
            
            if(progress > 40)
                System.exit(0);
            else if(progress == 40){
                    nextButton.setText("Finish");
                }


    The Full code for this segment in case It's necessary to see the whole thing

    Java Code:
    private void writeOut(){
            double loops = Double.parseDouble(jTextField2.getText())+1;
           double currentItem = Double.parseDouble(jTextField2.getText());
           int currentitem= Integer.parseInt(jTextField2.getText())+1;
           int things;
            String newOut;
            things = ((currentitem)-1)/4;
        try {
            FileWriter outFile = new FileWriter(templateFile, true);
            BufferedWriter outWriter = new BufferedWriter(outFile);
            PrintWriter output = new PrintWriter(outWriter);
            
            while(loops > 0 && progress <= 40){
                newOut = compileOutput();
                
                output.append(newOut);
                
                //jTextField1.setText(String.valueOf(--loops).indexOf(".") < 0 ? String.valueOf(loops) : String.valueOf(loops).replaceAll("0*$", "").replaceAll("\\.$", ""));
              //  if(currentItem>1){
               // things= things+(things-things)+1;
               //   }
                
                loops =progress;
                progress=things;
               ++things;
                jTextField2.setText(String.valueOf(things).indexOf(".") < 0 ? String.valueOf(things) : String.valueOf(things).replaceAll("0*$", "").replaceAll("\\.$", ""));
                jProgressBar1.setValue(things);
                jProgressBar1.setString(things + "/40");
            }
            
            outWriter.close();
            
            if(progress > 40)
                System.exit(0);
            else if(progress == 40){
                    nextButton.setText("Finish");
                }
            
    
             } 
               catch (IOException ex) {
               ex.printStackTrace();
               System.out.println("Write failed...");
             }
    
    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: can't get progress bar to count linearly?

    Please submit an Short, Self Contained, Correct Example that demonstrates the problem. It *must* be compilable with no syntax errors.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: can't get progress bar to count linearly?

    Note: For a testing program, instead of reading and writing files, use the Thread sleep() method to use a little time inside of the loop. The test program is for the GUI not the file I/O.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 0
    Last Post: 12-14-2014, 05:27 AM
  2. Progress Bar showing no progress
    By igorland in forum New To Java
    Replies: 8
    Last Post: 05-03-2013, 05:39 PM
  3. count every 45 records and prfix the count number
    By dkr786 in forum New To Java
    Replies: 8
    Last Post: 02-15-2013, 07:31 PM
  4. Progress Bar using Awt help
    By ynglsuresh in forum AWT / Swing
    Replies: 3
    Last Post: 03-28-2012, 07:33 AM
  5. Replies: 0
    Last Post: 03-01-2012, 12:21 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
  •