JDK-6413113 : JToolBar Buttons with wrong background color under XP Silver theme.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-04-13
  • Updated: 2010-04-02
  • Resolved: 2006-06-14
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.
JDK 7
7Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-beta2"
Java(TM) SE Runtime Environment (build 1.6.0-beta2-b79)
Java HotSpot(TM) Client VM (build 1.6.0-beta2-b79, mixed mode, sharing)


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


A DESCRIPTION OF THE PROBLEM :
When using the Windows Look and Feel under XP's "Silver" theme, tool bar buttons have the wrong background color. They show up in the wrong shade of gray and look terrible.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Steps to reproduce:
1) Go to the Windows Display Control Panel and hit the "Appearance" tab.
2) Under "Color Scheme" choose "Silver" (Blue and Olive work fine.)
3) Hit OK.
4) Launch the test program.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The tool bar buttons should have the same background as the toolbar.

ACTUAL -
The toolbar buttons are drawn in a slightly darker shade of gray.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import javax.swing.plaf.metal.OceanTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.DefaultMetalTheme;

public class ToolBarBackgroundBug extends JPanel {
	private static JFrame sMainFrame;

	public static void main(String[] args) {
		makeFrame(LandF.Platform);
	}

	private static void makeFrame(LandF landf) {
		if (sMainFrame != null) {
			sMainFrame.dispose();
		}
		landf.install();
		sMainFrame = new JFrame("ToolBarBackgroundBug");
		sMainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		sMainFrame.add(new ToolBarBackgroundBug(), BorderLayout.CENTER);
		sMainFrame.add(makeLandFButtons(), BorderLayout.WEST);
		sMainFrame.setBounds(10, 10, 600, 325);
		sMainFrame.setVisible(true);
	}

	public ToolBarBackgroundBug() {
		super(new BorderLayout());
		
		JToolBar toolbar = new JToolBar();
		JButton b1 = new JButton("JButton");
		Action actn = new AbstractAction("Action") {
			public void actionPerformed(ActionEvent e) { }
		};
		toolbar.add(b1);
		toolbar.addSeparator();
		toolbar.add(actn);
		add(toolbar, BorderLayout.NORTH);
	}

	private static JPanel makeLandFButtons() {
		JPanel pnl = new JPanel(new GridLayout(0, 1));
		LandF[] all = LandF.values();
		for (LandF lf : all)
			pnl.add(new JButton(lf.getAction()));
		JPanel outerPanel = new JPanel();
		outerPanel.add(pnl);
		return outerPanel;
	}

	private enum LandF {
		Platform(UIManager.getSystemLookAndFeelClassName()),
		Metal(MetalLookAndFeel.class.getName()),
		Ocean(UIManager.getCrossPlatformLookAndFeelClassName()),
		Motif(com.sun.java.swing.plaf.motif.MotifLookAndFeel.class.getName()),;
		final private String mName;
		private Action mAction;

		LandF(String name) {
			mName = name;
			mAction = new LandFAction(this);
		}

		public String getLFName() { return mName; }

		public void install() {
			try {
				UIManager.setLookAndFeel(getLFName());
				extra();
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (UnsupportedLookAndFeelException e) {
				e.printStackTrace();
			}
		}

		public Action getAction() {
			return mAction;
		}

		private void extra() throws UnsupportedLookAndFeelException {
			if (this == Metal) {
				System.err.println("Extra!");
				MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel();
				lf.setCurrentTheme(new DefaultMetalTheme());
				UIManager.setLookAndFeel(lf); // set it again
			} else if (this == Ocean) {
				MetalLookAndFeel lf = (MetalLookAndFeel) UIManager.getLookAndFeel();
				lf.setCurrentTheme(new OceanTheme());
				UIManager.setLookAndFeel(lf); // set it again
			}
		}
	}

	private static class LandFAction extends AbstractAction {
		private LandF mLookAndFeel;

		public void actionPerformed(ActionEvent e) { makeFrame(mLookAndFeel); }

		LandFAction(LandF lAndF) {
			super(lAndF.toString());
			mLookAndFeel = lAndF;
		}
	}
}

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

Comments
EVALUATION This is probably a duplicate of 6394735. I need to do more investigation.
18-04-2006