java - JProgress Bar with Values -
how can display text inside jprogressbar? i.e. "000/100"
progpanel.setborder(borderfactory. createemptyborder(10,10,10,10)); timerbar = new jprogressbar(0,100); timerbar.setorientation(jprogressbar.vertical); timerbarlabel = new jlabel("play"); timerbarlabel.setforeground(color.white); progpanel.add(timerbarlabel); progpanel.add(timerbar); this code progress bar.
as noted the documentation jprogressbar (i'm assuming using java 6), can use getvalue() method retrieve progress bar's current value boundedrangemodel.
so,
int maximum = timerbar.getmaximum(); int value = timerbar.getvalue(); // value 0 100 inclusive string text = string.format("%d/%d", value, maximum); the above result in text containing string "x/y", x current value of jprogressbar , y maximum value of same.
if want draw inside progress bar, may interested in setstring(string s) , setstringpainted(boolean b),
timerbar.setstringpainted(true); timerbar.setstring(text); and since value of progress bar changing, want update text each time value changes.
Comments
Post a Comment