JDK-6418117 : REGRESSION: Background of JToolBar can't be modified under XP look and feel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0,6
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-04-26
  • Updated: 2010-04-02
  • Resolved: 2006-07-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
5.0u9Fixed 6 b92Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b81)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b81, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
Firstly the background color of a JToolBar under the Windows XP Look&Feel is different from that in previous versions of Java (it's no longer the same color as JPanel). The background seems to be painted in such a way that it cannot be changed. Calling setBacground on a JToolBar instance has no effect neither does setOpaque.

I assume the XP Look&Feel is drawing the background without any regard to changes requested by calls to setBackground or setOpaque.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a JToolBar and try to change it's background color under the Windows XP look and feel, either by calling setBackground or setOpaque

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The background should change color. For instance calling setBackground(Color.RED) should result in the background of the toolbar being red.
ACTUAL -
There is no visible change to the toolbar when using the Windows XP look and feel (under Metal it does change which I assume suggests that this is an XP look and feel issue rather than an issue with JToolBar specifically)

REPRODUCIBILITY :
This bug can be reproduced always.

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

public class Test extends JFrame
{
	public static void main(String args[]) throws Exception
	{
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

		Test t = new Test();
		t.setVisible(true);
	}

	public Test()
	{
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		setSize(400,200);

		JPanel panel = new JPanel(new BorderLayout());
		panel.setBackground(Color.GREEN);

		JToolBar toolbar1 = new JToolBar();
		toolbar1.add(new JButton("Button 1"));
		toolbar1.add(new JButton("Button 2"));
		toolbar1.setBackground(Color.RED);

		JToolBar toolbar2 = new JToolBar();
		toolbar2.setOpaque(false);
		toolbar2.add(new JButton("Button A"));
		toolbar2.add(new JButton("Button B"));

		panel.add(toolbar1,BorderLayout.NORTH);
		panel.add(new JLabel("<html><body>Top toolbar should be red as background was set to <code>Color.RED</code><br><br>The bottom toolbar should be green as </code>setOpaque(false)</code> was called on the toolbar and the underlying <code>JPanel</code> has a background of <code>Color.GREEN</code>.</body></html>"),BorderLayout.CENTER);
		panel.add(toolbar2,BorderLayout.SOUTH);



		getContentPane().add(panel);
	}
}

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

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

Comments
EVALUATION Rather than completely drop painting the toolbar skin, it would be better to create a new version of XPStyle.Skin.paintSkin() to take a boolean indicating if it should check for a 'borderfill' skin. In this case it will skip painting the skin.
10-07-2006

EVALUATION The root cause of this bug is that we do not have a way to override the background of a component that is using an XP skin. Some components, like buttons, have other properties which allow this, but there is no general solution, nor a general definition, about what should happen when a developer sets the background color of a component that is drawn by the L&F using a skin. In order to fix this regression, and several other related bugs, I will comment out the usage of the XP skin for toolbars and create a new bug to address the larger opacity/bgcolor/skinning issue for Dolphin.
06-06-2006

EVALUATION The toolbar should draw based on the current visual style which ignores any set background color. This should be fixed at the same time as 6413113.
27-04-2006