Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add text on jprogressbar?

I am using a jprogressbar to indicate the availability status. i want to display a text of 40%[assumption] inside the progressbar. how to do it? the text was changed according to the availability value

like image 667
Siddhu Avatar asked Aug 02 '12 11:08

Siddhu


People also ask

How do I put text in progress bar?

Alliteratively you can try placing a Label control and placing it on top of the progress bar control. Then you can set whatever the text you want to the label.


3 Answers

You can use:

Initialising:

progressBar.setStringPainted(true);

Updating:

progressBar.setValue(newValue);
like image 188
Reimeus Avatar answered Sep 30 '22 00:09

Reimeus


  • Use setStringPainted(true) to show the Percentage of work completed.

  • Use setValue() which will help setting the incremental value and setString() to display the end message when done...

Here is an example from my code base :

final JProgressBar bar = new JProgressBar(0 , 100);  // 0 - min , 100 - max
bar.setStringPainted(true);
panel.add(bar);                   // panel is a JPanel's Obj reference variable

JButton butt = new JButton("start");
butt.addActionListener(){

    public void actionPerformed(){
        new Thread(new Runnable(){
            public void run(){
                int x = 0;
                while(x<=100) {
                    x++;
                    bar.setValue(x);        // Setting incremental values
                    if (x ==  100 ){
                        bar.setString("Its Done");   // End message
                        try{
                            Thread.sleep(200);
                        }catch(Exception ex){ }
                    }
                }).start();
            }
        });
like image 36
Kumar Vivek Mitra Avatar answered Sep 30 '22 01:09

Kumar Vivek Mitra


  • I am using a jprogressbar to indicate the availability status.

    please read tutorial about JProgressBar

  • i want to display a text of 40%[assumption] inside the progressbar.

    Using Determinate Progress Bars in the JProgressBar tutorial

  • how to do it? the text was changed according to the availability value

    more in the SwingWorker tutorial

like image 20
mKorbel Avatar answered Sep 30 '22 01:09

mKorbel