JDK-5032785 : XP L&F: REGRESSION: JTabbedPane.setBackgroundAt fails using System L&F 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-04-16
  • Updated: 2004-04-16
  • Resolved: 2004-04-16
Related Reports
Relates :  
Description

Name: gm110360			Date: 04/16/2004


FULL PRODUCT VERSION :
D:\temp>java -version
java version "1.4.2_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

FULL OS VERSION :
C:\>ver
Microsoft Windows XP [Version 5.1.2600]

It is "Windows XP Professional with Service Pack 1"

A DESCRIPTION OF THE PROBLEM :
JTabbedPane - setBackgroundAt does NOT set background color in Windows XP - SP1 if UIManager.getSystemLookAndFeelClassName() is used.

If the look and feel is changed to UIManager.getCrossPlatformLookAndFeelClassName(), then setting background (using setBackgroundAt) color works fine.

Please see sample code that I have put in the "Source Code" section, which fails to set colors for TABS under Windows XP - SP1 when using JRE 1.4.2_01.

I also experimented and observed that setting default color for JTabbedPane does NOT work. For example, the following code fails to make TAB background yellow under Windows XP - SP1 when using JRE 1.4.2.

  uiDefaults.put("TabbedPane.background", Color.yellow);


NOTE:
Replacing "UIManager.getSystemLookAndFeelClassName()" in the source code with "UIManager.getCrossPlatformLookAndFeelClassName()" sets colors properly. But, we like to use for our purpose.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the source code in the "Source Code" section.

Run it under "Windows XP Professional - Service Pack 1" that uses JRE 1.4.2_01 for running Java applications.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
TAB "One" should be green
TAB "Two" should be yellow
TAB "Three" should be red
TAB "Four" should be cyan
ACTUAL -
All TABs are shown in the same color with white background and colored (like, orange) border.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.JTabbedPane;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.UIManager;

import java.awt.*;
import java.awt.event.*;

public class TEMP_TABBED_PANE extends JPanel {

    public TEMP_TABBED_PANE() {
        JTabbedPane tabbedPane = new JTabbedPane();

        Component panel1 = makeTextPanel("Blah");
        tabbedPane.addTab("One", panel1);
        tabbedPane.setSelectedIndex(0);
        tabbedPane.setBackgroundAt(0, Color.green);

        Component panel2 = makeTextPanel("Blah blah");
        tabbedPane.addTab("Two", panel2);
        tabbedPane.setBackgroundAt(1, Color.yellow);

        Component panel3 = makeTextPanel("Blah blah blah");
        tabbedPane.addTab("Three", panel3);
        tabbedPane.setBackgroundAt(2, Color.red);

        Component panel4 = makeTextPanel("Blah blah blah blah");
        tabbedPane.addTab("Four", panel4);
        tabbedPane.setBackgroundAt(3, Color.cyan);

        //Add the tabbed pane to this panel.
        setLayout(new GridLayout(1, 1));
        add(tabbedPane);
    }

    protected Component makeTextPanel(String text) {
        JPanel panel = new JPanel(false);
        JLabel filler = new JLabel(text);
        filler.setHorizontalAlignment(JLabel.CENTER);
        panel.setLayout(new GridLayout(1, 1));
        panel.add(filler);
        return panel;
    }

    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch(Exception e) {
            e.printStackTrace();
        }

        JFrame frame = new JFrame("Tabbed Pane Demo for Color");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });

        frame.getContentPane().add(new TEMP_TABBED_PANE(),
                                   BorderLayout.CENTER);
        frame.setSize(400, 125);
        frame.setVisible(true);
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Replacing "UIManager.getSystemLookAndFeelClassName()" in the following code with "UIManager.getCrossPlatformLookAndFeelClassName()" sets colors properly. But, we like to use for our purpose.

Release Regression From : 1.3.1_11
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: 208849) 
======================================================================

Comments
EVALUATION The Windows XP L&F does not paint the tab background color because the background is never visible. The XP style "Luna" paints an image in the tab that totally covers it. Also see evaluation for bug 4880747. ###@###.### 2004-04-16
16-04-2004