Solved

JprogressBar / DB

Posted on 2004-03-22
9
540 Views
Last Modified: 2008-02-01
Hai i use Jprogress Bar for operation time to represent data fetching from database.
As the fetching time is not definite i use progressBar.setIndeterminate(true);
But this doesnt move until the data is fetched.
If i dont hide the progressbar i see it working after the data is fetched while fetching data it doesnt move.
Can anyone help me on this

my code is as below
for (int i = 0; i < 100; i++) {
progressBar.setIndeterminate(true);
progressBar.setValue (i);
paint(getGraphics());
}

Rgds
Mani
0
Comment
Question by:jackiemani
  • 4
  • 3
  • 2
9 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 total points
ID: 10654413
You should make sure that the fetching is done on another separate thread (not the gui one) or the gui won't update
0
 

Author Comment

by:jackiemani
ID: 10654434
Yes data is fethced seperately.Not in this logic.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10654445
In a dedicated thread?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10654471
i.e. (in pseudo) it should be:

public void actionPerformed(ActionEvent e) {
// Swing Timer actionPerformed
    if (taskDone == false) {
        incProgress();
    }
    else {
        stopIt();
    }
}

.............................


public void actionPerformed(ActionEvent e) {
   // handler of button or whatever kicks things off
   startTimer();
   Thread dataFetchThread = new Thread(new MyDataFetcher()); // MyDataFetcher is a Runnable
   dataFetchThread.start();
}
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 30

Expert Comment

by:mayankeagle
ID: 10656158
As a matter of fact, how do you propose to find out how much data has been fetched and show the appropriate limit on your JProgressBar? I mean - if 100 rows of data have to be fetched, how will you know that 60 have been fetched and 40 are pending, and so you have to show only 60% of progress in the JProgressBar?
0
 

Author Comment

by:jackiemani
ID: 10673474
Hi Chej,
I havent worked with threads,
can u support me with a sample code.
Actually we use DB componets to get the data from DB.
This is the Jdialog where in i show my Progress bar.

package htms.client.EXP.DlvyPlanList;

import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class PgBar extends JDialog {
  private JProgressBar progressBar;
  private Timer timer;
  public final static int ONE_SECOND = 1000;

  private String newline = "\n";
  private XYLayout xYLayout1 = new XYLayout ();
  Thread th = new Thread ();
  private XYLayout xYLayout2 = new XYLayout ();
  private XYLayout xYLayout3 = new XYLayout ();

  public PgBar (String title) {
    this.setTitle (title);

    try {
      jbInit ();
    }
    catch (Exception e) {
      e.printStackTrace ();
    }
  }

  private void jbInit () throws Exception {
    progressBar = new JProgressBar (0 , 100);
  this.getContentPane ().setLayout (xYLayout1);
    xYLayout1.setWidth (400);
    xYLayout1.setHeight (60);

     progressBar.setPreferredSize (new Dimension (300 , 20));
    progressBar.setBounds (23 , 29 , 300 , 23);
    progressBar.setMinimum (0);
    progressBar.setMaximum (20);
    progressBar.setValue (0);
    progressBar.setStringPainted (true);
    progressBar.setString ("Fetching Data ..........");
    progressBar.setBorder (BorderFactory.createLoweredBevelBorder ());
    this.getContentPane ().add (progressBar , new XYConstraints (23 , 29 , 357 , 23));

    progressBar.setIndeterminate (true);
    move (350 , 350);
      setSize (400 , 90);
      setVisible (true);
      System.out.println ("2");
      for (int i = 0; i < 100; i++) {
      progressBar.setIndeterminate (true);
      progressBar.setValue (i);
      paint (getGraphics ());
      Rectangle progressRect = new Rectangle (23 , 29 , 300 , 23); //progressBar.getBounds ();
      System.out.println (progressRect);
      progressRect.x = -20;
      progressRect.y = -20;
      progressBar.paintImmediately (progressRect);
      System.out.println (progressBar.getPercentComplete ());
      th.sleep (10);
      if (progressBar.getPercentComplete () == 0.95) {
      break;
      }
    }
    this.setModal (true);
  }

}


And in the main screen on the button action

 void jbRtrv_actionPerformed(java.awt.event.ActionEvent event) {
      theProgressBar =  new PgBar("Data Processing");
      entitySet.open();// Where entitySet is out own component
    }
Component has onopen and afterOpen methods rmtinf is the ejbconnection component
 void m_entitySet_onOpen(EntitySetEvent e) throws Exception {
             entitySet.setFetchedRecords(rmtInf.getCommonSelect(hashInqList));
       }
in After open the Progressbar is hidden.
   void m_entitySet_afterOpen(EntitySetEvent e) {
      theProgressBar.hide();
   }

Kindly suggest how to use Thread over this model source.


Rgds
Mani


hai mayankeagle
  I dont want to trace the DB data fetching just want a Indeterminate Progress bar to be shown so that user understands some action is done behind for getting the data and he has to wait for it.

Rgds
Mani



0
 
LVL 30

Assisted Solution

by:mayankeagle
mayankeagle earned 100 total points
ID: 10674295
You can just make a new Thread in the jbInit () method:

new Thread () {
  public void run ()  
  {
    for ( int i = 0 ; i < 100 ; i ++ )
    {
      progressBar.setValue ( i ) ;  

      try
      {
        Thread.sleep ( 10 ) ;
      }
      catch ( InterruptedException ie ) { }

    } // end of run ()

  }

}.start () ;

>> private JProgressBar progressBar;

Declare it as:

private final JProgressBar progressBar ;
0
 

Author Comment

by:jackiemani
ID: 10674596
Hi mayankeagle Thanks for the code!
And also thanks to Chej to directing in the right direction! I would split points for both.
Thanks a lot.
Mani
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 10682074
8-)
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 75
base64 decode encode 12 96
backtracking recursion  code 19 40
ArrayIndexOutOfBoundException 9 33
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now