aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JProgrssBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JProgrssBar" Watch "JProgrssBar" New topic
Author

JProgrssBar

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169
Dear Sirs,

Here is a program. When clickin a button a progreesbar is appear in indeterminata mode and setting some messages to a textarea. This is working.
But I want to display the bar independent of work of textarea. Please advise.




import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;


public class EmailerOne extends JFrame implements Runnable, ActionListener
{

JProgressBar myProgressBar;
JTextArea myTextArea;
JButton sendButton;
Thread runner;
static int NUMBEROFENTRIES = 10000;




public EmailerOne()
{
super("Mailing List Progress");
JPanel top = new JPanel();
top.setLayout(new FlowLayout());
myProgressBar = new JProgressBar();
myProgressBar.setValue(0);
myProgressBar.setVisible(false);
top.add(myProgressBar);

myTextArea = new JTextArea(8,30);
myTextArea.setLineWrap(true);
JScrollPane scroller = new JScrollPane(myTextArea);

JPanel bottom = new JPanel();
bottom.setLayout(new FlowLayout());
sendButton = new JButton("Send mail to mailing list.");
sendButton.addActionListener(this);
bottom.add(sendButton);

JPanel pane = new JPanel();
pane.setLayout(new BorderLayout());
pane.add("North", top);
pane.add("Center", scroller);
pane.add("South", bottom);

setContentPane(pane);

}



public void run()
{
sendButton.setEnabled(false);
myProgressBar.setVisible(true);

myProgressBar.setIndeterminate(true);


myTextArea.setText("");


int currentEntry = 0;
while(currentEntry < NUMBEROFENTRIES)
{

myTextArea.append("Sending Message to: " +"joby "+currentEntry+ "\n");

currentEntry++;

}


myTextArea.append("\nCompleted Sending of Messages\n");


myProgressBar.setIndeterminate(false);
myProgressBar.setVisible(false);
sendButton.setEnabled(true);
}

public void actionPerformed(ActionEvent userInteractiveEvent)
{
Object sourceOfEvent = userInteractiveEvent.getSource();
if (sourceOfEvent == sendButton)
{

Thread runner = new Thread(this);
runner.start();
}
}

public static void main(String[] args)
{

EmailerOne frame = new EmailerOne();
WindowListener listener = new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
};
frame.addWindowListener(listener);
frame.pack();
frame.setVisible(true);
}
}

thanks in advance
Steffen Reinhard
Greenhorn

Joined: Jun 13, 2005
Posts: 19
Originally posted by francis varkey:
Dear Sirs,

Here is a program. When clickin a button a progreesbar is appear in indeterminata mode and setting some messages to a textarea. This is working.
But I want to display the bar independent of work of textarea. Please advise.



Hi Francis,

your JProgressBar is working independently from any action in your JTextArea, as you never set any value. Immediately after creation your JProgressBar starts displaying errrr... indeterminate progress. That is, it starts jogging along happily but doesn't really show any real progress. Try the following code (and mind I just put in the JLabel for demonstration purposes, the JProgressBar is really controlled by the value of the counter variable):




There is, however, a class javax.swing.ProgressMonitor which pops up a configurable dialog with a JProgressBar, the usual ok/cancel buttons and a message that can be customized to meet your specific needs.


Hope this helps.

Cheers,

Steffen

[ January 04, 2007: Message edited by: Steffen Reinhard ]
[ January 04, 2007: Message edited by: Steffen Reinhard ]
francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 169
My aim is to develope a program using swing and jdbc. when clicking a button ,datas are selecting from table and show it to a JTable.But this take few time. During this waiting time I want to show a JProgresbar with indetermianate mode(because I cant calculate the time ,is it correct?).when getting data in JTable ,the JProgreebas must going to determinate mode and invisible.For this I developed a program ,which is the above program. Instead of setting JTextarea I want to load data from database . mean while progreesbar showing any interrupts.can you please give some code with respect to my first program without using Timer class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JProgrssBar