Search code examples
javaswinglook-and-feelcolor-schemejprogressbar

Color in JProgressBar


enter image description hereI just wanted to use the Windows L&F in a JFrame. Now while using a progress bar, the default color is green, similar to the one used in other windows functions like copying of files, etc. Sometimes you might have seen, windows displays a 'RED' - colored progress (when there may be an overwrite in case of copying of files). How can I use that 'RED' color in case of my progress bar, instead of setting the 'foreground color' to 'RED', which looks different?


Solution

  • Java implements the native looking progress bar using their own code. It doesn't support the Vista and newer features that indicate stalled/slow progress by changing the color of the bar.

    The source that draws the bar is available to examine; it uses the paintSkin method to paint the bar, which by default, only paints in one color.

    The design guidelines for progress bar use on Windows indicate that you should:

    • Use red or yellow progress bars only to indicate the progress status, not the final results of a task. A red or yellow progress bar indicates that users need to take some action to complete the task. If the condition isn't recoverable, leave the progress bar green and display an error message.
    • Turn the progress bar red when there is a user recoverable condition that prevents making further progress. Display a message to explain the problem and recommend a solution. Turn the progress bar yellow to indicate either that the user has paused the task or that there is a condition that is impeding progress but progress is still taking place (as, for example, with poor network connectivity). If the user has paused, change the Pause button label to Resume. If progress is impeded, display a message to explain the problem and recommend a solution.