Java Program to create a vertical ProgressBar

Java 8Object Oriented ProgrammingProgramming

To create a vertical ProgressBar, use the following property −

JProgressBar.VERTICAL

Set it like this −

JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL,0, 1000);

The following is an example to create a vertical ProgressBar −

Example

package my;
import java.awt.Color;
import javax.swing.*;
public class SwingDemo extends JFrame {
   JProgressBar progressBar;
   int i = 0;
   SwingDemo() {
      progressBar = new JProgressBar(JProgressBar.VERTICAL,0, 1000);
      progressBar.setBounds(70, 50, 120, 30);
      progressBar.setValue(0);
      progressBar.setStringPainted(true);
      add(progressBar);
      setSize(550, 150);
      setLayout(null);
   }
   public void inc() {
      while (i <= 1000) {
         progressBar.setValue(i);
         i = i + 50;
         try {
            Thread.sleep(100);
         } catch (Exception e) {}
      }
   }
   public static void main(String[] args) {
      SwingDemo s = new SwingDemo();
      s.setVisible(true);
      s.inc();
   }
}

Output

raja
Updated on 30-Jul-2019 22:30:26

Advertisements