Create a JProgressBar Component with an Unknown Maximum in Java

Description

The following code shows how to create a JProgressBar Component with an Unknown Maximum.

Indeterminate mode: Progress bar bounces back and forth from side to side

Example


//  w  w w.  j a  va2  s  .c  o  m

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class Main extends JFrame {

  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    int min = 0;
    int max = 100;
    JProgressBar progress = new JProgressBar(min, max);

    // Play animation
    progress.setIndeterminate(true);
    
    getContentPane().add(progress, BorderLayout.NORTH);
    pack();
    setVisible(true);
  }

  public static void main(String arg[]) {
    new Main();
  }
}

The code above generates the following result.

Create a JProgressBar Component with an Unknown Maximum in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer