How to add text on jprogressbar?
Solution 1
You can use:
Initialising:
progressBar.setStringPainted(true);
Updating:
progressBar.setValue(newValue);
Solution 2
Use
setStringPainted(true)
to show the Percentage of work completed.Use
setValue()
which will help setting the incremental value andsetString()
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();
}
});
Solution 3
-
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
Solution 4
This will show the progress inside the bar
progressBar.setStringPainted(true);
Solution 5
This shows the progress percentage inside the progress bar
progressBar.setStringPainted(true);
Siddhu
Updated on July 09, 2022Comments
-
Siddhu almost 2 years
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