United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6418117 REGRESSION: Background of JToolBar can't be modified under XP look and feel
6418117 : REGRESSION: Background of JToolBar can't be modified under XP look and feel

Details
Type:
Bug
Submit Date:
2006-04-26
Status:
Resolved
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2006-07-19
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0,6
Fixed Versions:
6

Related Reports
Backport:
Duplicate:
Duplicate:
Duplicate:
Duplicate:
Relates:

Sub Tasks

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.
                                     
2006-07-10
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.
                                     
2006-06-06
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.
                                     
2006-04-27



Hardware and Software, Engineered to Work Together