• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JProgrssBar

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic