Results 1 to 9 of 9
  1. #1
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default Progress Bar showing no progress

    Hello!
    I have a slider and a progress bar that should show the value installed by the slider and, of course, showing progress by filling the bar. Everything works except that the bar is not filling -- not showing progress, although it does show the values selected by the slider. Have no clue why...

    Java Code:
    		sliderPnl4CargoAft.addChangeListener(new ChangeListener() {
    			public void stateChanged(ChangeEvent e) {
    				JSlider source = (JSlider)e.getSource();
    				int valueCargoAft = 0;
    				valueCargoAft = source.getValue();
    				deltaCargoAft = weightCargoAllowedLb - addCargoLoadedForwardLb;
    				maxSliderCargoAft = weightCargoAllowedLb - addCargoLoadedForwardLb;
    				if (maxCompCapAft <= deltaCargoAft)	{
    					maxSliderCargoAft = maxCompCapAft;
    				}
    				addCargoLoadedAftLb = maxSliderCargoAft * valueCargoAft / 100;
    				addCargoLoadedTotalLb = addCargoLoadedForwardLb + addCargoLoadedAftLb;
    				fldPnl4CargoLoadedTotalLb.setText(format0comma.format(addCargoLoadedTotalLb));
    
    				addCargoLoadedTotalKg = addCargoLoadedTotalLb * 0.45359237;;
    				fldPnl4CargoLoadedTotalKg.setText(format0comma.format(addCargoLoadedTotalKg));
    				
    				weightPayloadTotalLb = weight.getPayloadTotalWeightLb(addCargoLoadedTotalLb);
    				weightPayloadTotalKg = weightPayloadTotalLb * 0.45359237;
    				
    				weightZFWlb = weight.getWeightZFWLb();
    				weightZFWkg = weightZFWlb * 0.45359237;
    				fldPnl4TotalZfwLb.setText(format0comma.format(weightZFWlb));
    				fldPnl4TotalZfwKg.setText(format0comma.format(weightZFWkg));
    				
    				progbarPnl4CargoAft.setString(format0comma.format(addCargoLoadedAftLb));
    				
    			}
    		});
    		
    		
    		progbarPnl4CargoAft = new JProgressBar();
    		progbarPnl4CargoAft.setString("0");
    		progbarPnl4CargoAft.setForeground(Color.BLUE);
    		progbarPnl4CargoAft.setStringPainted(true);
    		progbarPnl4CargoAft.setBounds(725, 255, 538, 24);
    		pnl4.add(progbarPnl4CargoAft);
    Thank you for your help!
    Last edited by igorland; 05-03-2013 at 04:27 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,439
    Rep Power
    18

    Default Re: Progress Bar showing no progress

    You need some debugging in there then.
    You're flying blind at the moment and hoping to spot the error...that doesn't work very often.
    Please do not ask for code as refusal often offends.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default Re: Progress Bar showing no progress

    I don't see where you set the value of the progress bar anywhere; read the API description of the SwingWorker class for a clear example how to use a progress bar.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,439
    Rep Power
    18

    Default Re: Progress Bar showing no progress

    Not so sure.
    I did think that originally, but lookin at it it looks like the progress bar represents the total load, and the sliders are for load forward and aft (for example).
    So it's not using the progress bar to mark progress of some work, but to mark a total amount.

    But you're right, though, there's no sign of the bar havign any values set.
    Please do not ask for code as refusal often offends.

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default Re: Progress Bar showing no progress

    Even then: the setValue( ... ) method is the only way to set/change the value of a progress bar and I don't see it anywhere in the code (the code reminds me of that darn Hungarian notation somehow ...)
    Setting the string value of a progress bar doesn't change its value and a progress bar is way too stupid to 'progress' its value itself.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,439
    Rep Power
    18

    Default Re: Progress Bar showing no progress

    Don't you need to set the max value as well?
    Otherwise it doesn't know what relationship the numbers you are providing bear to the length of the bar.
    Please do not ask for code as refusal often offends.

  7. #7
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default Re: Progress Bar showing no progress

    Quote Originally Posted by Tolls View Post
    Don't you need to set the max value as well?
    Otherwise it doesn't know what relationship the numbers you are providing bear to the length of the bar.
    Yup, that too, otherwise it defaults to 100(%). I didn't even look that far because of those funky variable names ... What I dislike most about those progress bars is when no Strings are printed, the progress bar displays a nice, fresh, lively, green bar but when you dare to make it print a String, it changes it colour to a dull, dusty, boring blue-ish; stupid MS Windows system look ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    igorland is offline Member
    Join Date
    Jan 2013
    Posts
    25
    Rep Power
    0

    Default Re: Progress Bar showing no progress

    Guys, first of all, thank you. I did oversaw including setValue(). Actually, I did include it in the beginning-- it did not show the progress anyways, would just instantly move to the end when I moved a slider. Then I removed it, then thought that setString() might replace it, then... I do not know what happened then. So, I put it back and put setMaximum() and that helped! It is working now as intended.
    Second of all, what is exactly wrong with the variable names? When having hundreds of variables, this actually helps me a great deal to remain organized -- I know exactly which variable to use and it is easy to copy, paste and edit them, when needed. I am familiar with Hungarian notation, agree, my variables resemble them (some of them are). Although I do not see anything wrong in it. If this is a big no-no in the Java community, please let me know, I would appreciate hearing it.
    Third, yes that blue is not good. I used it to experiment with the code, but will have something more eye-friendly.
    In any case, thank you all so much, that was indeed helpful!

  9. #9
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    12,995
    Blog Entries
    7
    Rep Power
    19

    Default Re: Progress Bar showing no progress

    Of course there's no law against the use of Hungarian notation, it's just that I find it (nearly) unreadable and it isn't necessary for Java: Java is a statically, strongly typed language and HN doesn't add anything to the language. But feel free to use it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Progress Bar using Awt help
    By ynglsuresh in forum AWT / Swing
    Replies: 3
    Last Post: 03-28-2012, 07:33 AM
  2. Replies: 0
    Last Post: 03-01-2012, 12:21 PM
  3. Progress bar
    By Milanek in forum New To Java
    Replies: 0
    Last Post: 10-11-2011, 04:41 PM
  4. JProgressBar not showing progress during process
    By george_ in forum AWT / Swing
    Replies: 1
    Last Post: 08-27-2011, 11:35 AM
  5. How to use Progress bar
    By LankanSniper in forum AWT / Swing
    Replies: 3
    Last Post: 03-25-2009, 10:44 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
  •