Java Progress BarProgress 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 barProgressBar.java Output: 2. Program to create a vertical progress barProgressBar1.java Output: 3. Program to set specific string to Progress BarProgressBar3.java Output 1: Output 2: Output 3: Output 3: Constructors of the JProgressBar Class- 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.
- 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.
- JProgressBar(int min, int max) : Creates a progress bar with specified minimum and maximum value.
- 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- int getMaximum( ) : Returns the maximum value of the progress bar.
- int getMinimum( ) : Returns the minimum value of the progress bar.
- String getString( ) : Gets the string representation of the current value of the progress bar.
- void setMaximum(int n) : Sets the maximum value of the progress bar to the value n.
- void setMinimum(int n) : Sets the minimum value of the progress bar to the value n.
- void setValue(int n) : Sets the current value of the progress bar to the value n.
- void setString(String s) : Sets the value of the progress String to the String s.
- 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.
|