I tried the attached example but the progress bar doesn't show up until I 
manually resize the frame. Any idea? Thanks.

Qinghuai
import java.awt.*;
import javax.swing.*;
        
class JProgressBarTest extends SwingBase {
    public static void main(String argv[]) 
        {JProgressBarTest doit = new JProgressBarTest();}

    public JProgressBarTest() {
        JProgressBar code_bar = new JProgressBar(0,100);
        code_bar.setStringPainted(true);
        add(code_bar, BorderLayout.CENTER);
        window.setSize(300, 200);
        revalidate();
        repaint();

        for (int count=0; count<100; count++) {
            code_bar.setValue(count);
            revalidate();
            repaint();
            try {Thread.sleep(100);} catch(InterruptedException err) {}
        }
        code_bar.setValue(100);
        System.out.println("Finished");
    }
}
        
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class SwingBase extends JPanel {
    protected static final JFrame   window  = new JFrame();
    private   static final String   title   = new String("Swint Test");

    public SwingBase() {
        window.setTitle(title);
/*
        try {
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            SwingUtilities.updateComponentTreeUI(window);
        }
            catch(UnsupportedLookAndFeelException error) {}
            catch(ClassNotFoundException          error) {}
            catch(InstantiationException          error) {}
            catch(IllegalAccessException          error) {}
*/
            this.setLayout(new BorderLayout());
            window.addWindowListener(new GoodBye());
            window.getContentPane().add(this, BorderLayout.CENTER);
            window.pack();
            window.setVisible(true);
        }

        protected class GoodBye extends WindowAdapter implements ActionListener {
            public void windowClosing(WindowEvent even) {
            Terminator();
        }
        public void actionPerformed(ActionEvent even) {
            Terminator();
        }
    }

    protected void Terminator() {
        System.exit(0);
    }
}
        

Reply via email to