JDK-4765247 : JTabbedPane background cannot be set when no tabs present
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2002-10-18
  • Updated: 2002-11-22
  • Resolved: 2002-11-22
Related Reports
Relates :  
Description

Name: sv35042			Date: 10/18/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

FULL OPERATING SYSTEM VERSION :Microsoft Windows XP
[Version 5.1.2600]


EXTRA RELEVANT SYSTEM CONFIGURATION :
I have a standard Pentium 4 system with a sound card,
a network card, and a CD-R.

A DESCRIPTION OF THE PROBLEM :
If no tab is present in a JTabbedPane, the background is
always light gray, despite calling setBackground() for
the tabbed pane. When a tab is present, the background above
the tab shows correctly. This same problem existed in 1.3,
but adding the JTabbedPane to a JPanel having the desired
color caused the correct background to display when no tab
was present on the tabbed pane.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1.Create a JTabbedPane.
2.Create a JPanel with BorderLayout
3.Set the background color of the panel to Color.green.
4.Set the background color of the tabbed pane to
Color.green.
4.Add the tabbed pane to the CENTER portion of the panel.
5.Add the panel to the CENTER of a JFrame.

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expect the JTabbedPane backround to be green or expect
the background of the JPanel that contains the tabbed
pane to show green.

This bug can be reproduced always.

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

public class Test extends JFrame
{
	JTabbedPane t;

	public Test()
	{
		Container content = getContentPane();

		t = new JTabbedPane();
		t.setBackground(Color.green);

		JPanel w = new JPanel();
		w.setBackground(Color.green);
		w.setLayout(new BorderLayout());
		w.add(t, BorderLayout.CENTER);

		content.add(w, BorderLayout.CENTER);
		setSize(300,300);
		setTitle("JTabbedPane Test");
		setVisible(true);

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	void x()
	{
		try
		{
			Thread.sleep(5000);
		}
		catch (InterruptedException ie)
		{}

		t.addTab("Test", new JPanel());
	}

	public static void main(String[] args) throws Exception
	{
		Test t = new Test();

		t.x();
	}
}

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

CUSTOMER WORKAROUND :
Make the JTabbedPane invisible until it has a tab.
(Review ID: 147099) 
======================================================================

Comments
EVALUATION I believe the following is happening. When there are no tabs there is no room reserved for the tab area, you only have the tab pane content area which will paint grey. Once you add a tab the tab pane content is resized to fit the tabs and then you see the background. I don't believe this is a bug, but I will investigate this more before it is closed. ###@###.### 2002-10-18 Yes, the background color for the tabbed pane is only used for the tabs not the content area. This was filed as bug 4261116 and was fixed in 1.4.0. This behavior will not be changed. ###@###.### 2002-11-22
22-11-2002