JProgressBar.setValue problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    JProgressBar.setValue problem.

    HI friends I am recently working on Swing.
    But face a strange Problem!

    I pass a JProgressBar reference and there I am doing a lot of database operation or others. There JProgressBar.se tValue is not working. Actually there i importing a data into database from file. In the loop I am setting the value. But it's not working.
    Why does this happen??


    Debasis Jana
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    You have to be careful from which thread you invoke most Swing methods:

    Concurrency in Swing

    You would think JProgressBar's setValue method would be thread-safe, but the API doesn't vouchsafe for this. When I use a JProgressBar and I am updating it from another thread, I play it safe and use EventQueue.invo keLater.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by BigDaddyLH
      You have to be careful from which thread you invoke most Swing methods:

      Concurrency in Swing

      You would think JProgressBar's setValue method would be thread-safe, but the API doesn't vouchsafe for this. When I use a JProgressBar and I am updating it from another thread, I play it safe and use EventQueue.invo keLater.
      Ok Thanks.
      I got your point and saw the link.
      But if I want to dispatch the event from another Thread then what should I do?
      Suppose I am calling the importing method and inside importing method I am updating the "setValue" after each row insertion.
      How get I achieve?

      Debasis Jana

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by dmjpro
        But if I want to dispatch the event from another Thread then what should I do?
        Have a look at the SwingUtilities class. It can start a Runnable in the
        AWT thread for you. btw, never do any real work in that thread yourself, i.e. it makes
        the GUIs react slow because their thread is busy doing your work.

        kind regards,

        Jos

        Comment

        • Tian Angel
          New Member
          • May 2018
          • 1

          #5
          Actually I get in such problem ,too !
          It almost drives me crazy ,but I don't know how to handle this.

          Comment

          Working...