Example usage for javax.swing JProgressBar setUI

List of usage examples for javax.swing JProgressBar setUI

Introduction

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

Prototype

@BeanProperty(hidden = true, visualUpdate = true, description = "The UI object that implements the Component's LookAndFeel.")
public void setUI(ProgressBarUI ui) 

Source Link

Document

Sets the look-and-feel object that renders this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    JProgressBar progressBar = new JProgressBar();
    progressBar.setOpaque(false);/*from  www  . j  a v  a 2  s  .  c o  m*/
    progressBar.setUI(new GradientPalletProgressBarUI());

    JPanel p = new JPanel();
    p.add(progressBar);
    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);
}

From source file:Main.java

public Main() {
    JProgressBar jpb = new JProgressBar();
    jpb.setUI(new MyProgressUI());
    jpb.setForeground(Color.blue);
    jpb.setIndeterminate(true);//www  .  ja  v a 2 s .c  om
    this.add(jpb);

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(this);
    f.pack();
    f.setVisible(true);
}