Results 1 to 9 of 9
Thread: Progress Bar showing no progress
- 05-03-2013, 05:24 AM #1
Member
- Join Date
- Jan 2013
- Posts
- 89
- Rep Power
- 0
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);
Last edited by igorland; 05-03-2013 at 05:27 AM.
- 05-03-2013, 10:45 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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.
** This space for rent **
- 05-03-2013, 10:56 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 05-03-2013, 11:48 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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.
** This space for rent **
- 05-03-2013, 12:14 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 05-03-2013, 12:39 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
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.
** This space for rent **
- 05-03-2013, 12:57 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Progress Bar showing no progress
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,
JosBuild a wall around Donald Trump; I'll pay for it.
- 05-03-2013, 04:25 PM #8
Member
- Join Date
- Jan 2013
- Posts
- 89
- Rep Power
- 0
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!
- 05-03-2013, 06:39 PM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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,
JosBuild a wall around Donald Trump; I'll pay for it.
Similar Threads
-
Progress Bar using Awt help
By ynglsuresh in forum AWT / SwingReplies: 3Last Post: 03-28-2012, 08:33 AM -
Connecting progress bar/ progress monitor to a task
By Ami in forum AWT / SwingReplies: 0Last Post: 03-01-2012, 01:21 PM -
Progress bar
By Milanek in forum New To JavaReplies: 0Last Post: 10-11-2011, 05:41 PM -
JProgressBar not showing progress during process
By george_ in forum AWT / SwingReplies: 1Last Post: 08-27-2011, 12:35 PM -
How to use Progress bar
By LankanSniper in forum AWT / SwingReplies: 3Last Post: 03-25-2009, 11:44 AM
Bookmarks