The Java Developers Almanac 1.4


Order this book from Amazon.

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

e803. Getting and Setting the Values of a JProgressBar Component

    // To create a progress bar, see e801 Creating a JProgressBar Component
    
    // Get the current value
    int value = progress.getValue();
    
    // Get the minimum value
    int min = progress.getMinimum();
    
    // Get the maximum value
    int max = progress.getMaximum();
    
    
    // Change the minimum value
    int newMin = 0;
    progress.setMinimum(newMin);
    
    // Change the maximum value
    int newMax = 256;
    progress.setMaximum(newMax);
    
    // Set the value; the new value will be forced into the bar's range
    int newValue = 33;
    progress.setValue(newValue);
It is also possible to set all the values at once by using the model:
    progress.getModel().setRangeProperties(newValue, 0, newMin, newMax, false);

 Related Examples
e801. Creating a JProgressBar Component
e802. Creating a JProgressBar Component with an Unknown Maximum
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.