Javatpoint Logo
Javatpoint Logo

Java Progress Bar

Progress Bar is an horizontal or vertical bar that visualize the progress of an operation. The class that is used to render the progress bar is 'JProgressBar' that is the part of the Java Swing package. It displays the progress of specific task by filling of the bar and/or displaying the percentage of completion. It may even display the text as specified. As the task reaches its completion, the progress bar fills up.

1. Creating a horizontal progress bar

ProgressBar.java

Output:

Java progress bar

2. Program to create a vertical progress bar

ProgressBar1.java

Output:

Java progress bar

3. Program to set specific string to Progress Bar

ProgressBar3.java

Output 1:

Java progress bar

Output 2:

Java progress bar

Output 3:

Java progress bar

Output 3:

Java progress bar

Constructors of the JProgressBar Class

  1. JProgressBar( ) : Creates a default horizontal progress bar with no text on it. It sets a minimum and initial value of 0 and a maximum of 100.
  2. JProgressBar(int orientation) : Creates a progress bar with a specified orientation, that is vertical or horizontal bar. If 'SwingConstants.VERTICAL' is passed as anzargument to this method, a vertical progress bar is created and if 'SwingConstants.HORIZONTAL' is passed as an argument a horizontal progress bar is created.
  3. JProgressBar(int min, int max) : Creates a progress bar with specified minimum and maximum value.
  4. JProgressBar(int orientation, int min, int max) : Creates a progress bar with the specified minimum and maximum value and orientation. A vertical progress bar is created when SwingConstants.VERTICAL is passed as an argument, and a horizontal progress bar is created if SwingConstants.HORIZONTAL is passed as an argument.

Methods of the JProgressBar Class

  1. int getMaximum( ) : Returns the maximum value of the progress bar.
  2. int getMinimum( ) : Returns the minimum value of the progress bar.
  3. String getString( ) : Gets the string representation of the current value of the progress bar.
  4. void setMaximum(int n) : Sets the maximum value of the progress bar to the value n.
  5. void setMinimum(int n) : Sets the minimum value of the progress bar to the value n.
  6. void setValue(int n) : Sets the current value of the progress bar to the value n.
  7. void setString(String s) : Sets the value of the progress String to the String s.
  8. setStringPainted(Boolean b) : The 'stringPainted' property determines whether the progress bar should render a progress string. The default value is false, meaning no string is painted. We can set the value to true or false.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA