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
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.
You can use:
Initialising:
progressBar.setStringPainted(true);
Updating:
progressBar.setValue(newValue);
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();
}
});
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With