Example usage for javax.swing JProgressBar JProgressBar

List of usage examples for javax.swing JProgressBar JProgressBar

Introduction

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

Prototype

public JProgressBar() 

Source Link

Document

Creates a horizontal progress bar that displays a border but no progress string.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel panel1 = new JPanel();
    JPanel panel2 = new JPanel();

    JButton button = new JButton();

    Main f = null;/*from w w  w . j ava  2s .  co m*/
    f = new Main();

    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(700, 400);

    panel1.setLayout(new BorderLayout());
    panel1.setForeground(Color.white);
    button.setText("Convert");
    panel1.add(button, BorderLayout.SOUTH);

    f.setContentPane(panel1);
    f.setVisible(true);

    f1 = new Main();

    f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f1.setSize(457, 100);
    f1.setTitle("Conversion Progress");
    f1.setLocationRelativeTo(null);

    panel2.setLayout(new BorderLayout());
    panel2.setForeground(Color.white);

    JProgressBar progressBar = new JProgressBar();
    progressBar.setValue(35);
    progressBar.setStringPainted(true);

    panel2.add(progressBar, BorderLayout.SOUTH);

    f1.setContentPane(panel2);

    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            f1.setVisible(true);
        }
    });
}

From source file:Main.java

/**
 * @return//  ww w.  j  a v a2  s.  c  o m
 */
private static JProgressBar createProgressBar() {
    JProgressBar progressBar = new JProgressBar();
    progressBar.setIndeterminate(true);
    progressBar.setIndeterminate(false);
    progressBar.setMaximum(100);
    progressBar.setValue(100);
    return progressBar;
}

From source file:Main.java

public Main() {
    pbar = new JProgressBar();
    pbar.setMinimum(min);//from  w  w w .j  a  va2 s. com
    pbar.setMaximum(max);
    add(pbar);

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(this);
    frame.pack();
    frame.setVisible(true);

    for (int i = min; i <= max; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    updateBar(percent);
                }
            });
            Thread.sleep(100);
        } catch (InterruptedException e) {
        }
    }
}

From source file:Main.java

public Main() {
    JProgressBar jpb = new JProgressBar();
    jpb.setUI(new MyProgressUI());
    jpb.setForeground(Color.blue);
    jpb.setIndeterminate(true);/*from  w ww .j  a  v  a 2s.  c  om*/
    this.add(jpb);

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

From source file:InvokeAndWaitExample.java

public InvokeAndWaitExample() {
    this.keepRunning = true;
    this.progressThread = new ProgressThread();

    this.progressBar = new JProgressBar();
    this.progressBar.setMaximum(100);

    add(this.progressBar);
    System.out.println(keepRunning);
    this.progressThread.start();
}

From source file:SwingProgressBarExample.java

public SwingProgressBarExample() {
    pbar = new JProgressBar();
    pbar.setMinimum(MY_MINIMUM);
    pbar.setMaximum(MY_MAXIMUM);
    add(pbar);
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(300, 200);//from  w w  w .j av a  2s . c  o m
    blocker = new JDialog(this, true);
    blocker.setLayout(new FlowLayout());
    blocker.add(new JLabel("I'm blocking EDT!"));
    JProgressBar progress = new JProgressBar();
    progress.setIndeterminate(true);
    blocker.add(progress);
    blocker.pack();

    timer = new Timer(3000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doSomeWork();
        }
    });
    timer.setRepeats(false);
    timer.start();
}

From source file:Main.java

public Main() {
    setSize(300, 100);// www  .j av  a2s  .c  om

    UIManager.put("ProgressBar.selectionBackground", Color.black);
    UIManager.put("ProgressBar.selectionForeground", Color.white);
    UIManager.put("ProgressBar.foreground", new Color(8, 32, 128));

    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Thread runner = new Thread() {
                public void run() {
                    counter = minValue;
                    while (counter <= maxValue) {
                        Runnable runme = new Runnable() {
                            public void run() {
                                progressBar.setValue(counter);
                            }
                        };
                        SwingUtilities.invokeLater(runme);
                        counter++;
                        try {
                            Thread.sleep(100);
                        } catch (Exception ex) {
                        }
                    }
                }
            };
            runner.start();
        }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:JProgressBarDemo.java

public JProgressBarDemo() {
    super("JProgressBar Demo");
    setSize(300, 100);//from  ww  w .  j a  v a 2 s  .  co m

    UIManager.put("ProgressBar.selectionBackground", Color.black);
    UIManager.put("ProgressBar.selectionForeground", Color.white);
    UIManager.put("ProgressBar.foreground", new Color(8, 32, 128));

    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Thread runner = new Thread() {
                public void run() {
                    counter = minValue;
                    while (counter <= maxValue) {
                        Runnable runme = new Runnable() {
                            public void run() {
                                progressBar.setValue(counter);
                            }
                        };
                        SwingUtilities.invokeLater(runme);
                        counter++;
                        try {
                            Thread.sleep(100);
                        } catch (Exception ex) {
                        }
                    }
                }
            };
            runner.start();
        }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:SplashScreen.java

public SplashScreen(final BufferedImage img) {
    JPanel panel = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g.create();

            g2d.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), SplashScreen.this);
        }// w  w w . jav a  2s.  c om
    };
    panel.setPreferredSize(new Dimension(img.getWidth(), img.getHeight()));

    Container content = getContentPane();
    content.setLayout(new BorderLayout());
    content.add(panel, BorderLayout.NORTH);
    content.add(label = new JLabel(), BorderLayout.CENTER);
    content.add(bar = new JProgressBar(), BorderLayout.SOUTH);
    pack();
    setLocationRelativeTo(null);
}