Example usage for javax.swing JProgressBar setOpaque

List of usage examples for javax.swing JProgressBar setOpaque

Introduction

In this page you can find the example usage for javax.swing JProgressBar setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:Main.java

public static void main(String[] args) {
    JProgressBar progressBar = new JProgressBar();
    progressBar.setOpaque(false);
    progressBar.setUI(new GradientPalletProgressBarUI());

    JPanel p = new JPanel();
    p.add(progressBar);/*from  www.ja v a  2  s  . c om*/
    p.add(new JButton(new AbstractAction("Start") {
        @Override
        public void actionPerformed(ActionEvent e) {
            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
                @Override
                public Void doInBackground() {
                    int current = 0, lengthOfTask = 100;
                    while (current <= lengthOfTask && !isCancelled()) {
                        try {
                            Thread.sleep(50);
                        } catch (Exception ie) {
                            return null;
                        }
                        setProgress(100 * current / lengthOfTask);
                        current++;
                    }
                    return null;
                }
            };
            worker.addPropertyChangeListener(new ProgressListener(progressBar));
            worker.execute();
        }
    }));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(p);
    frame.setSize(320, 240);
    frame.setVisible(true);
}