Java JProgressBar .setStringPainted (boolean b)

Syntax

JProgressBar.setStringPainted(boolean b) has the following syntax.

public void setStringPainted(boolean b)

Example

In the following code shows how to use JProgressBar.setStringPainted(boolean b) method.


//from  w w  w . j  a v a  2s  .c o m
    
import java.awt.BorderLayout;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.border.Border;

public class Main {
  public static void main(String args[]) {
    JFrame f = new JFrame("JProgressBar Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JProgressBar progressBar = new JProgressBar();
    progressBar.setValue(25);
    progressBar.setStringPainted(true);
    Border border = BorderFactory.createTitledBorder("Reading...");
    progressBar.setBorder(border);
    f.add(progressBar, BorderLayout.NORTH);
    f.setSize(300, 100);
    f.setVisible(true);
  }
}