• 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 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

JTable JProgressBar

 
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


Hello
I am creating a jtable jprogressbar
for now I happen to display my music in the jtable
I will change music afterwards
but my biggest problem is to operate each progress bar for each music
I intend to use swingututies.invokelater or swingworker
I could have documented and saw on the API that one had to use one or the other
Thank you for your help
 
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

creating a jtable jprogressbar


Can you explain what the relationship will be between the table and the progress bar?  What duration will be measured by the progress bar?
 
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
The jtable displays what is in the folder and plays the duration of the music that is 16 seconds each but I will change music afterwards to see if the progress bar ends well at the same time as the duration of each music
I do not know how to take it for the code
Should I do a loop array for all boxes (columns)?
I am thinking
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you explain what the JTable does that needs a progress bar to measure? I do not understand how a JTable is related to a progress bar.
 
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 have trouble explaining you,
I saw some codes where the jtable is linked to progress bars
 
Sheriff
Posts: 22116
114
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now the ProgressRenderer isn't used anywhere. You need to tell the JTable to use it for rendering some column.

Unfortunately, the progress bars in the table will not be updated automatically like a regular progress bar. That's because the renderer controls in a JTable aren't the controls themselves, they are just use for rendering. For progress bars that means you get a snapshot. The trigger to update it comes not from the progress bar but from the table (most likely its table model). Indeterminate mode won't work properly, period. For non-indeterminate mode you need to tell the progress bar the current value for each column; that's one of the arguments to the getTableCellRendererComponent method.
 
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
ok I understand
 
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


java.io.FileNotFoundException: sounds (Accès refusé)
at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:153)
at java.desktop/com.sun.media.sound.SunFileReader.getAudioInputStream(SunFileReader.java:117)
at java.desktop/javax.sound.sampled.AudioSystem.getAudioInputStream(AudioSystem.java:1062)
at Test.main(Test.java:35)
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "javax.sound.sampled.AudioInputStream.getFormat()" because "audioInputStream" is null
at Test.main(Test.java:42)


I am trying to find how to get the lasts in seconds to insert them into the jtable, I do not know if it is possible
Here's the mistake
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.io.FileNotFoundException: sounds


The jvm could not find the sounds file.  Where is it located?  It should be in the current directory when the program executes.

Looking at the code, it appears sounds is the name of a directory, not the name of a sound file.  If that is the case, then the arg to the getAudioInputStream method needs to be changed to refer to a file that has sound.  For example: files[0] would be one of the files in the sounds folder.
 
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
OK, thanks
For line 49, to get the durations in seconds
a bit like getName for the names of the songs,
there is no getduration inseconds, I'm looking for the APIs
Is there a way to display them with Get or other?
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

to get the durations in seconds


Does the code in lines 35-44 do that?
If so move that code to a method and call it to set the value of the second column.
 
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 put files [0] at line 35
For now the Code works but does not give the lasts in seconds, I do not think the code does that
I am asking me if we must not do a array of seconds of seconds
 
Saloon Keeper
Posts: 7999
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
Have you put in a print statement to see what is really in durationInSeconds ?
 
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
yes I did a system.out.println
it gives it well in seconds only the first song
I put songs of different seconds

just to try, I also put durationInSeconds at line 49
it says the lasts in seconds in the jtable but these are the same times for different songs, it takes into account the first song
 
Carey Brown
Saloon Keeper
Posts: 7999
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 need to make the following code into a method called public double getSeconds( File file )
Then modify this code
 
Carey Brown
Saloon Keeper
Posts: 7999
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
"row" only takes Objects so you'd have to convert the double to a Double before assigning it to row[1].
 
Carey Brown
Saloon Keeper
Posts: 7999
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
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 returned the GetSeconds method and creates a field and it shows 0.0 for songs
 
Carey Brown
Saloon Keeper
Posts: 7999
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
Lines 32-44 should go into the getSeconds() method.
 
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 so much
I did not understand that the lines 32-44 should be integrated into the GetSeconds method
 
Carey Brown
Saloon Keeper
Posts: 7999
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
Let's see what you have now. I only have a few more minutes before bed.
 
Carey Brown
Saloon Keeper
Posts: 7999
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
Good night. Leave me what you have and I'll look at it in the morning.
 
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


good night

here is the code
 
Carey Brown
Saloon Keeper
Posts: 7999
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
Seems like you only need seconds in a long not a double. And I'm guessing that even an int would hold the number of seconds that you're likely to be dealing with (check me on this). So this code needs some clean up. First of all change the return type of the method to be a long. Then change this code
to
No need to perform the  division in floating point and no need to put the result in a temporary variable.

Lastly you'll have to change your row[1] = Double... to row[1] = Long....
 
Carey Brown
Saloon Keeper
Posts: 7999
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
One problem that you're going to have to clean up at some point is that you are not closing the input stream in the getSeconds() method. You will eventually run out of resources depending on how long your list of files is. The best way to guarantee that the resource is closed is  by using try-with-resources. Sorry, I don't have a link to a tutorial but Google should help you find one.
 
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
ok i put long a return and method and row [i]
and the seconds are displayed as an int that is to say without point
and I'm going to look at that treating resources
 
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
ok I just watched a little the Try with Resources
I just quickly took a look
If I understood correctly to use TRY and FINALY to close the streams
 
Carey Brown
Saloon Keeper
Posts: 7999
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 should only need the TRY unless you are also trying to catch exceptions. Probably not finally.
 
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
ok I'm going to document me on it to understand
 
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 have an example of Try with Resources of Java 9
I have trouble placing or modifying my code by following the example
 
Carey Brown
Saloon Keeper
Posts: 7999
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
No. You have to do the actual opening inside TRY( ... )
 
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 keep you informed of my research, I will try some codes, I wonder if you do not use clip.open ()
 
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 galley a little, I found that
with Try (AudioInputStream) is error
LOCAL VARIABLE COUNT DEFINED IN AN ENCLOSING SCOPE MUST BE FINAL OR EFFECTIVELY FINAL
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please copy the full text of the error message and paste it here. It has important info about the error.

Have you read the tutorial:  https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
 
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
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Local variable audioInputStream defined in an enclosing scope must be final or effectively final

at JTable08.getSeconds(JTable08.java:63)
at JTable08.main(JTable08.java:41)

it is line 5
 
Carey Brown
Saloon Keeper
Posts: 7999
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:No. You have to do the actual opening inside TRY( ... )


Note that you have code after the block that will need to be moved into the block to get access to the opened resource.
 
Norm Radder
Master Rancher
Posts: 4250
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

into the block to get access to the opened resource.


Obviously something is not as I expected here:
 
Carey Brown
Saloon Keeper
Posts: 7999
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 give up)

 
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
OK, thanks
Every time, I was not far, I even made a return 0
I did not think to do audiosystem.getaudioinPutstream (file) with AudioInputStream AudioInputStream
I was very bonded with cast with targetdataline with file
thank you again
 
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
There are still other things to know like Try with Resources, EDT, Swingworker, Swingutilities.invokelater ...

Otherwise I will go to the progress bars with the jtable
 
Morning came much too soon and it brought along a friend named Margarita Hangover, and a 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