Win a copy of Secure Financial Transactions with Ansible, Terraform, and OpenSCAP this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

JProgressBar Array

 
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I try to make a table of 15 bars of progression.
I wonder if it is possible
Thank you for your help
 
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:


Sure, it's possible.

On line 1 you have a VARIABLE named JProgressBar. You don't want that, it's name is already the name of a common swing class, not a variable, and variable names should always begin with a lower case letter.

On line 5 you create a LOCAL variable for each progress bar which disappears each time around the loop. You need to keep a reference to it in an array so that you can access it to set its value. And somewhere, perhaps inside the loop, you need to add the object to a swing component, such as a JPanel.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see how to do it
I'm wondering if we don't need fifteen references
can you clarify me a little more?
 
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use

can you explain why you need all those ProgressBars?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a music album or a jukebox
each song will have its progression bar following the song's time
the songs are written in JLabel
I'm wrong because as each album does not necessarily have 15 songs
that's why I try to create lots of progress bars
 
Marshal
Posts: 72478
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you reading an album? How does it tell you how many tracks it has?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I opened a sounds folder and put 15 songs in it
a bit like an images folder where we put the images
 
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it looks like you got your answer about how to create and fill an array of JProgressBars. Or am I wrong?
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you need a progressbar only for the song that is playing. Why would each song have its own progressbar?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I prefer a progress bar for each song than a bar for 15 songs
even though I was given the answer, I haven't found the answer yet.
here is my answer

it does not work
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course it doesn't work. You need some other code which does something with the progress bars.
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:

it does not work


Have a look at line 1. Notice anything wrong here? And what about line 6? A JProgressBar extends Container, so it does have an 'add' method. But after that line, what is bars[i]?
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You seem to have some misconceptions about how to utilize the JProgressBar class. I suggest getting a single bar to work first and then consider what it would take to make and control an array of them.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Piet Souris
Saloon Keeper
Posts: 4358
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was a 1D array insufficient?    

Two remarks:

1) make a print of your 2D array, after all the PBs have been created.

2) what is it that makes you say: "it works"?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you want me to do System.print.out?
it works because it gives what I want by pressing run
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:it works because it gives what I want by pressing run



You get a frame with 45 progress bars, right? So yeah, that's progress.

We see a fair number of posts here where people post 300 lines of code and say "It doesn't work", and it doesn't work because the 300 lines are all wrong. Small steps, like what you did, are much better. So good work so far, onwards to the next step.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
better start small and end big
also ask if I can do better by improving the code
 
Paul Clapham
Marshal
Posts: 26493
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say the code was fine for a first step. There's still a long way to go.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I created a button and found a piece of code
since it is an array of progress bars
I don't know how to explain it to you
Do you have any advice to give me ?.
thank you
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing that 'jb' is a JButton, so you'd need one of those if you are going to exercise this code. And last seen you didn't have a 'jpb', you had a JProgressBar[][] bars instead.

Have you tried printing out bars as suggested?
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no I did not print but it works with run
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:no I did not print but it works with run


NOT THE SAME
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it means that I have to redo the code but using system out print
what will it bring me?
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here. Took all of two seconds. Now see if you still think "it works".
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this code works by pressing run but after all
I tell myself that with tables of progress bars it could not work with actionperformed with a button
I don't know where you are coming from
tell me the bottom of your mind
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, what was the output of the print?
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if you replaced the print with;
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I no longer have progress bars but a window
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I no longer have progress bars but a window
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you running this from an IDE or Windows or some other environment. I'm assuming that you get both a console (either on the IDE or on a command line window) that will display the output of any print statements, and also get a graphic window displaying your progress bars. I some cases one lays on top of the other so you can't see the console window unless you minimize your progress bar window.
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Figuring out how to get to the console window is extremely useful for debugging.

Note: Don't launch your program with "javaw" (note the 'w') when doing this, it will typically suppress the console window, use the plain vanilla "java".
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ronald deux wrote:I no longer have progress bars but a window


Does the window display anything? Text perhaps?
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The console window should be completely blank except for a single word
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
excuse me, I redid the code to add a button
the console displays
Exception in thread "main" java.lang.NullPointerException
at Test.main (Test.java:43)

by using the old code
it's the same exception
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:What if you replaced the print with;


If you did this you would have gotten a null pointer exception.
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that's good null point exception
it's not the same as null
 
ronald deux
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you want me to understand debugging or use window and console at the same time
 
Carey Brown
Saloon Keeper
Posts: 8020
70
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A null in the wrong place will cause a null pointer exception.

 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic