JDK-5047032 : REGRESSION: XP L&F: Background color on JProgressBar does not work in WinXP
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.2
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-05-13
  • Updated: 2004-05-24
  • Resolved: 2004-05-24
Related Reports
Relates :  
Relates :  
Relates :  
Description

Name: rmT116609			Date: 05/13/2004


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Envrionment, Standard Edition (build 1.4.2-b28)
Java HotSpot (TM) Clinet VM (build 1.4.2-b28, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows XP Version 2002 SP 1

A DESCRIPTION OF THE PROBLEM :
Setting the background color on JProgressBar does not work in XP L&F in JRE 1.4.2. This used to work in 1.4.1. Even in 1.4.2, with other L&F like metal L&F, it works properly and shows the background color set on the component. With XP L&F, it always shows white background.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the test case.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The progress bar should show with red color as background. When the task proceeds, the progress is indicated by the green foreground color.
ACTUAL -
The progress bar shows up with white background color, which is then filled with green foreground color.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ProgressBar extends JPanel {

    private JProgressBar progressBar;

    public ProgressBar() {
        super(new BorderLayout());


        progressBar = new JProgressBar(0, 20);
        progressBar.setValue(0);
        progressBar.setStringPainted(true);
        progressBar.setForeground(Color.green);
        progressBar.setBackground(Color.red);
        progressBar.setOpaque(true);


        JPanel panel = new JPanel();
        panel.add(progressBar);

        add(panel, BorderLayout.PAGE_START);
        setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));


    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("ProgressBarDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Create and set up the content pane.
        JComponent newContentPane = new ProgressBar();
        newContentPane.setOpaque(true); //content panes must be opaque
        frame.setContentPane(newContentPane);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {

      try
        {
 
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e)
        { }
       createAndShowGUI();
    }
}
---------- END SOURCE ----------

Release Regression From : 1.4.1
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Incident Review ID: 265350) 
======================================================================

Comments
EVALUATION The XP Look & Feel uses the system style information to paint components. In the Luna style, the progress bar is painted using system images, so the background and foreground colors do not apply. See also evaluations of bugs 4880747 and 4881191. ###@###.### 2004-05-24
24-05-2004