How to create Vertical progress bar occupying the entire frame in Java

Java 8Object Oriented ProgrammingProgramming

For this, create a vertical progress bar −

JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL);
progressBar.setEnabled(true);

Also, set the bounds −

progressBar.setBounds(70, 50, 120, 30);

The following is an example to create vertical progress bar occupying the entire frame −

Example

package my;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class SwingDemo {
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL);
      progressBar.setEnabled(true);
      progressBar.setBounds(70, 50, 120, 30);
      progressBar.setBackground(Color.orange);
      progressBar.setForeground(Color.white);
      progressBar.setStringPainted(true);
      progressBar.setString("1000");
      progressBar.setValue(20);
      frame.setLayout(new BorderLayout());
      frame.add(progressBar, BorderLayout.CENTER);
      frame.setSize(600, 400);
      frame.setVisible(true);
   }
}

Output

raja
Published on 04-Jun-2019 07:05:59
Advertisements