Java Swing How to - Create non changeable Vertical progress bar with background








Question

We would like to know how to create non changeable Vertical progress bar with background.

Answer

import java.awt.BorderLayout;
import java.awt.Color;
//from w w  w  .  ja  v a 2  s.co m
import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class Main {

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

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

    bar.setBackground(Color.YELLOW);
    bar.setForeground(Color.GREEN);

    bar.setStringPainted(true);
    bar.setString("2000 g");
    bar.setValue(65);
    frame.setLayout(new BorderLayout());
    frame.add(bar, BorderLayout.CENTER);
    frame.setSize(500, 400);
    frame.setVisible(true);
  }
}