The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples] > JProgressBar  [5 examples]

e802. Creating a JProgressBar Component with an Unknown Maximum

A progress bar with an unknown maximum typically displays an animation until the task is complete.

Note: The percentage display should not be enabled when the maximum is not known (e804 Displaying the Percentage Done on a JProgressBar Component).

    // Create a horizontal progress bar
    int min = 0;
    int max = 100;
    JProgressBar progress = new JProgressBar(min, max);
    
    // Play animation
    progress.setIndeterminate(true);
When information on the task's progress is available, the progress bar can be made determinate:
    int value = 33;
    progress.setValue(value);
    progress.setIndeterminate(false);

 Related Examples
e801. Creating a JProgressBar Component
e803. Getting and Setting the Values of a JProgressBar Component
e804. Displaying the Percentage Done on a JProgressBar Component
e805. Listening for Value Changes in a JProgressBar Component

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.