change color of JProgressBar

Posted on 2008-11-08
Last Modified: 2013-12-14
i have a JProgressBar which I am using during a Task

is it possible to change the color of progress bar (default is orange to say green) when the process is finished,

Question by:max_dub
    1 Comment
    LVL 13

    Accepted Solution

    Your task already has a way to let your JProgressbar now the current progress (set the value of the JProgressbar). At the end of your task you can also let it change the color:
    import javax.swing.*;
    import java.awt.*;
    import java.util.Random;
    import java.util.concurrent.TimeUnit;
    public class Test extends JFrame {
        private JProgressBar bar;
        public static void main(String[] args) throws Exception {
            Test test = new Test();
            Task task = new Task(test);
            new Thread(task).start();
        protected void frameInit() {
            bar = new JProgressBar(0, 100);
        public void setProgress(int value) {
        public void setFinished() {
    class Task implements Runnable {
        private Test feedback;
        public Task(Test test) {
   = test;
        public void run() {
            try {
                Random rnd = new Random();
                int value = 0;
                while (value < 100) {
                    TimeUnit.MILLISECONDS.sleep(rnd.nextInt(400) + 300);
                    value += rnd.nextInt(25) + 5;
                    value = Math.min(value, 100);
            } catch (InterruptedException e) {

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now