Search code examples
javaswingjprogressbar

Displaying a custom progress string on a JProgressBar


When setStringPainted() of JProgressBar is used,the amount of process completion is displayed in terms of percentage.

But how can i customise setStringPainted() so that i can display remaining time instead of percentage?


Solution

  • setString() sets the progress string. If that property is null then only a simple percentage is shown. This is pointed out clearly in the documentation:

    setString

    public void setString(String s)

    Sets the value of the progress string. By default, this string is null, implying the built-in behavior of using a simple percent string. If you have provided a custom progress string and want to revert to the built-in behavior, set the string back to null.

    The progress string is painted only if the isStringPainted method returns true.

    Parameters:

    s – the value of the progress string