• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JTable JProgressBar

 
Saloon Keeper
Posts: 8704
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Ranch Hand
Posts: 230
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok
 
ronald deux
Ranch Hand
Posts: 230
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I added some pieces of codes, it still works, I fill it little by little
I will start by functioning a single progress bar with a song
after it's more difficult

Have I done the code well?
What is still missing?

I know it is necessary to add actionperformed, actionListener
 
Carey Brown
Saloon Keeper
Posts: 8704
71
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
Beautiful. Cleanly formatted. And appreciate you posting your (mostly) finished product.

Only comments I have are nits.

Future enhancements:
  • Set names column wider, or better yet, use a layout manager to let it size itself.
  • Right justify duration column.
  • Display duration in 00:00:00.000 format.
  • Strip off trailing spaces in code.


  •  
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    ah yeah I have a cow
    there is more than to milk
    where do you want me to put it

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


    How to view 100 throughout the Progress column with three songs for example?
    it works a bit only the third line 100 that displays the Progress column
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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 are calling sleep() while you're on the EDT. Not a good thing to do. That's where a SwingWorker would come in handy.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I will use swingworker afterwards
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "javax.swing.SwingWorker.execute()" because "JTable09.worker" is null
    at JTable09.actionPerformed(JTable09.java:92)
    at JTable09.lambda$0(JTable09.java:64)
    at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
    at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
    at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
    at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
    at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
    at java.desktop/java.awt.Component.processMouseEvent(Component.java:6614)
    at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
    at java.desktop/java.awt.Component.processEvent(Component.java:6379)
    at java.desktop/java.awt.Container.processEvent(Container.java:2263)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4990)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
    at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4919)
    at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4548)
    at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4489)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2769)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4822)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)


    This is my code with swingworker
    I do not have the habit
    I have surely made mistakes
    I have trouble with chunks
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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've declared "worker" but you haven't initialized it to anything, so it is null.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    I initialize swingworker
    it works but there is always null
    I add this code that allows you to display Completed or Error
     it's from there comes the null error
    It's still the last line that displays 100% with three songs, I can not operate the latest column
    it must be used to use getselectedcolumn according to this I understood
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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 created your own "Worker" class to override SwingWorker, which is the correct thing to do. However you are not instantiating a "Worker" here. Also I don't see anywhere in your code where you initialize your "worker" variable.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    I give you the code
    I have not stopped adding code, for now I start to understand a little swingworker
    If I added useless code, let me know
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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
    It "worked" for me after I put in a check for  null.
    Of course you are currently using the last row not the selected row.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Oh, I thought I could operate the latest selection column and not the selection line
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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
    Last row and last column.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I do not really understand
    If I delete the selection line
    Why is it the first line that works and not all the column with three songs
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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
    This is where it pays to be careful with your variable names. You called it "rows" but in fact it represents a "row".
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    it does not change anything
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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
    Sure it does. Try this.

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


    here is a code
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    How to make for progress bars or rows work one after the other
    for example when the first progress bar ends
    The second begins
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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:

    Before moving forward you need to fix this. The way you've got it the call  to model.setValue() is being done off of the EDT and it needs to be done on the EDT. This call was supposed to be placed inside the worker process() method.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    if I understood all the code or simply setValueAt
    so it does not work anymore
    I do not know what I did
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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. Now you put everything that was supposed to be off the EDT (e.g. sleep) back on the EDT. ONLY the model.setValue() goes in process(). Put everything else back where it was.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    The method update(Graphics) in the type JComponent is not applicable for the arguments (int)

    at JTable09$2.process(JTable09.java:123)
    at java.desktop/javax.swing.SwingWorker$3.run(SwingWorker.java:423)
    at java.desktop/sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
    at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.run(SwingWorker.java:847)
    at java.desktop/sun.swing.AccumulativeRunnable.run(AccumulativeRunnable.java:112)
    at java.desktop/javax.swing.SwingWorker$DoSubmitAccumulativeRunnable.actionPerformed(SwingWorker.java:857)
    at java.desktop/javax.swing.Timer.fireActionPerformed(Timer.java:310)
    at java.desktop/javax.swing.Timer$DoPostEvent.run(Timer.java:242)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:316)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
    Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
    The method update(Graphics) in the type JComponent is not applicable for the arguments (int)


    I thought it had to move the block
    sorry, I found it weird because I saw that we had to put setvalueat to the process method
    sorry again
    I put update, I'm not sure that you have to put it, anyway, error
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thank you for this code
    I just tested it
    This is exactly what I was looking for  
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    while I was on the process method
    I have benefited to watch 00: 00: 00.00 for seconds
     
    Bartender
    Posts: 4667
    183
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Carey Brown wrote:(...)Before moving forward you need to fix this. The way you've got it the call  to model.setValue() is being done off of the EDT and it needs to be done on the EDT. This call was supposed to be placed inside the worker process() method.


    I've been thinking about this. The model is not created on the EDT so updating it from the EDT or from the SwingWorkers thread, I don't think it matters. But I find it very confusing (the Renderer IS created on the EDT), so I could be wrong.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I did not know that Swingworker had to be used but when I saw on the API, I understood
    a bit like swingutilities.invokelater
    before I did not look much the API
    now I look at
    I do not have the habit yet
    I spend more time looking for or documenting me what to practice the code
    I start understanding use
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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:while I was on the process method
    I have benefited to watch 00: 00: 00.00 for seconds


    This would probably be useful:
    https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/time/Duration.html
    There should also be a simple way to format it.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    thank you carey
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I continue to search for the format 00: 00: 00.000
    But I ask myself a question
    This code allows it to play music?
    Have you managed to play music, Carey?
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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

    Somewhere I have some code for an MP3 player. It doesn't have a progress bar though.
     
    ronald deux
    Ranch Hand
    Posts: 230
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I am asking me if I do not have to start the code again
     
    Carey Brown
    Saloon Keeper
    Posts: 8704
    71
    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 am asking me if I do not have to start the code again

    Don't understand the question?
     
    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    reply
      Bookmark Topic Watch Topic
    • New Topic