Java Swing Tutorial - Java JProgressBar.getValue()








Syntax

JProgressBar.getValue() has the following syntax.

public int getValue()

Example

In the following code shows how to use JProgressBar.getValue() method.

//from www  . j  a v  a2  s.  c  o m

import javax.swing.JProgressBar;

public class Main {
  public static void main(String[] argv) throws Exception {
    int minimum = 0;
    int maximum = 100;
    JProgressBar progress = new JProgressBar(minimum, maximum);
    // 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);

  }
}