0

I tired to set a text into a Jprogress bar by using setString method.. But it wasn't... So what do i do for that.. here is my code...

    import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MyFrame extends JFrame{
    JProgressBar pro_bar = new JProgressBar(0,100);
    MyFrame(){
        pro_bar.setSize(400,20);
        pro_bar.setLocation(50,65);
        add(pro_bar);
        setLayout(null);    
        setSize(500,150); 
        setResizable(false);
        setDefaultCloseOperation(3);
        setLocationRelativeTo(null);
        setVisible(true);
        for(int i=0;i<100;i++){

            pro_bar.setValue(i);
            pro_bar.setString(null);

            try {Thread.sleep(100);}catch (Exception e){}
        }
    }
}
class Demo{
    public static void main(String args[]){
        System.out.println("hello");
        MyFrame f1=new MyFrame();   
    }
}

1 Answers1

0

You're missing just one thing.

pro_bar.setStringPainted(true);
pro_bar.setValue(i);
pro_bar.setString(i +"%");

Set setStringPainted value to true before you set the String and the value.

m4heshd
  • 773
  • 9
  • 23