Hi can you help me please how can i change the color of progressbar or just look like in windows xp progress bar...please help me...thank you in advance hoping for your positive responds...

never try it before, but apparently changing properties of UIManager before creating progress bar should work. Something like this

UIManager.put("ProgressBar.selectionBackground",Color.BLUE);
UIManager.put("ProgressBar.selectionForeground",Color.WHITE);
JProgressBar progressBar.....

never try it before, but apparently changing properties of UIManager before creating progress bar should work. Something like this

UIManager.put("ProgressBar.selectionBackground",Color.BLUE);
UIManager.put("ProgressBar.selectionForeground",Color.WHITE);
JProgressBar progressBar.....

hi sir thank you for the reply i will try this sir and i will write again if get trouble..more power to you...

never try it before, but apparently changing properties of UIManager before creating progress bar should work. Something like this

UIManager.put("ProgressBar.selectionBackground",Color.BLUE);
UIManager.put("ProgressBar.selectionForeground",Color.WHITE);
JProgressBar progressBar.....

sir please help me on this it will not change the color...please correct me sir...thank you in advance hoping for your positive responds...

import java.awt.*;
import java.awt.event.*;
import javax.swing.*; 

public class Progress extends JFrame {

    JProgressBar current;
    JTextArea out;
    JButton find;
    Thread runner;
    int num = 0;

  
    public Progress() {
        super("Progress");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      
        JPanel pane = new JPanel();
      
        UIManager.put("ProgressBar.selectionBackground",Color.BLUE);
        UIManager.put("Progress.selectionForeground",Color.GREEN);
        pane.setLayout(new FlowLayout());
        current = new JProgressBar(0, 2000);
        
        
        
        current.setValue(0);
        current.setStringPainted(true);
        pane.add(current);
        setContentPane(pane);
        
    }


    public void iterate() {
        while (num < 2000) {
            current.setValue(num);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) { }
            num += 95;
        }
    }

    public static void main(String[] arguments) {
       
        Progress frame = new Progress();
        frame.pack();
        frame.setVisible(true);
        frame.iterate();
      
      
   }
}

As you named the JprogressBar as current
Change the following in code also,Hope it works!

UIManager.put("current.selectionBackground",Color.BLUE);
UIManager.put("current.selectionForeground",Color.GREEN);

As you named the JprogressBar as current
Change the following in code also,Hope it works!

UIManager.put("current.selectionBackground",Color.BLUE);
UIManager.put("current.selectionForeground",Color.GREEN);

Nah that wouldn't.
I will give it one more shot, I will look up source code for one of the L&F projects I know and see if I find something there

OK here is solution, enjoy it!

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class JProgressBarDemo extends JFrame {

  protected int minValue = 0;

  protected int maxValue = 100;

  protected int counter = 0;

  protected JProgressBar progressBar;

  public JProgressBarDemo() {
    super("JProgressBar Demo");
    setSize(300, 100);

    UIManager.put("ProgressBar.background", Color.BLACK); //colour of the background
    UIManager.put("ProgressBar.foreground", Color.RED);  //colour of progress bar
    UIManager.put("ProgressBar.selectionBackground",Color.YELLOW);  //colour of percentage counter on black background
    UIManager.put("ProgressBar.selectionForeground",Color.BLUE);  //colour of precentage counter on red background


    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Thread runner = new Thread() {
          public void run() {
            counter = minValue;
            while (counter <= maxValue) {
              Runnable runme = new Runnable() {
                public void run() {
                  progressBar.setValue(counter);
                }
              };
              SwingUtilities.invokeLater(runme);
              counter++;
              try {
                Thread.sleep(100);
              } catch (Exception ex) {
              }
            }
          }
        };
        runner.start();
      }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    addWindowListener(wndCloser);
    setVisible(true);
  }

  public static void main(String[] args) {
    new JProgressBarDemo();
  }
}

OK here is solution, enjoy it!

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class JProgressBarDemo extends JFrame {

  protected int minValue = 0;

  protected int maxValue = 100;

  protected int counter = 0;

  protected JProgressBar progressBar;

  public JProgressBarDemo() {
    super("JProgressBar Demo");
    setSize(300, 100);

    UIManager.put("ProgressBar.background", Color.BLACK); //colour of the background
    UIManager.put("ProgressBar.foreground", Color.RED);  //colour of progress bar
    UIManager.put("ProgressBar.selectionBackground",Color.YELLOW);  //colour of percentage counter on black background
    UIManager.put("ProgressBar.selectionForeground",Color.BLUE);  //colour of precentage counter on red background


    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        Thread runner = new Thread() {
          public void run() {
            counter = minValue;
            while (counter <= maxValue) {
              Runnable runme = new Runnable() {
                public void run() {
                  progressBar.setValue(counter);
                }
              };
              SwingUtilities.invokeLater(runme);
              counter++;
              try {
                Thread.sleep(100);
              } catch (Exception ex) {
              }
            }
          }
        };
        runner.start();
      }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    addWindowListener(wndCloser);
    setVisible(true);
  }

  public static void main(String[] args) {
    new JProgressBarDemo();
  }
}

hello sir thank you for the reply helping me... i will try this sir and i will write again if i have doubt...more power to you sir...thanks...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.