Hi,
I have problem with displaying JProgressBar. Application should show the indeterminate Progress indicator during the complex operations.
Attached
Java Code
public class ProgressBarTest extends JFrame{
private JProgressBar progressBar = new JProgressBar(0, 100);
private JButton btnTest = new JButton("Test Indeterminate Progress Bar");
public ProgressBarTest(){
//initializes the components in the JFrame
initFrame();
}
private void initFrame(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(progressBar, BorderLayout.NORTH);
add(btnTest, BorderLayout.SOUTH);
progressBar.setPreferredSize(new Dimension(200,25));
btnTest.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean indeterminate = progressBar.isIndeterminate();
// starts progress indicator
progressBar.setIndeterminate(true);
progressBar.repaint();
///////////////////////////////////////////////////////////
// This is the place where complex operation takes place //
///////////////////////////////////////////////////////////
// This is a dummy operation.
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
///////////////////////////////////////////////////////////
// Complex Operation Ends here. //
///////////////////////////////////////////////////////////
// stops progress indicator
progressBar.setIndeterminate(false);
}
});
pack();
}
public static void main(
String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ProgressBarTest().setVisible(true);
}
});
}
}
Thanks in Advance
Elango Ramaraj