JDK-4685800 : JTabbedPane.setOpaque(false) does not follow opacity rules
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-05-15
  • Updated: 2017-05-23
Related Reports
Relates :  
Description
Name: jk109818			Date: 05/15/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 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
JTabbedPane.setOpaque(false) does not behave as it did in
1.3.  I filed this as a bug and recieved this in the
response:

This new behavior is part of a fix done for the 1.4
release.  Please see the following bug reports for more
information:
http://developer.java.sun.com/developer/bugParade/bugs/4629510.html
AND
http://developer.java.sun.com/developer/bugParade/bugs/4261116.html

Seems like the fix for 4261116 could have been handled
differently.  Setting a component to transparent should do
just that.  If special behaviour is required in some cases,
other methods could have been added to control these
behaviours...like the border.

Now JTabbedPane seems to violates the opacity rule by
painting a lot of pixels that it should not need to; making
programs that benefitted from the previous behaviour break.

Since I am not the only one concerned about this change, I
am resubmitting this bug as an RFE (it might fit into the
EOU category as well, since getting the 1.3 behaviour is
not intuitive).  This way we can see which way other
developers think this should be handled.

In any case, it would be nice if the old functionality
would be available without subclassing the UI.


REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See description and sample program

EXPECTED VERSUS ACTUAL BEHAVIOR :
See description and sample program

This bug can be reproduced always.

---------- BEGIN SOURCE ----------

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JTabbedPaneTester extends JFrame implements ActionListener {
	private JTabbedPane tabbedPane;
	private int index = 0;
	public JTabbedPaneTester() {
		JToolBar tb = new JToolBar();
		JButton b = new JButton("Add tab");
		b.addActionListener(this);
		tb.add(b);
		getContentPane().add(tb,BorderLayout.NORTH);
		
		tabbedPane = new JTabbedPane();

		JPanel p = new JPanel(new BorderLayout());
		p.setOpaque(true);
		p.setBackground(Color.white);
		p.add(tabbedPane,BorderLayout.CENTER);
		
		getContentPane().add(p,BorderLayout.CENTER);
		setSize(500,300);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});
		show();
	}
	public void actionPerformed(ActionEvent e) {
		JPanel p = new JPanel();
		p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
		p.setOpaque(false);
		
		index++;
		
		JLabel l = new JLabel("Opaque label on tab " + index);
		l.setOpaque(true);
		p.add(l);
		
		l = new JLabel("Non opaque label on tab " + index);
		l.setOpaque(false);
		p.add(l);
		tabbedPane.add("Tab " + index,p);
	}
	public static void main(String[] argv) {
		JTabbedPaneTester t = new JTabbedPaneTester();
	}
	
}
---------- END SOURCE ----------
(Review ID: 146561) 
======================================================================

Comments
EVALUATION This issue has support from both sides. We will look into adding some type of API to controlling the painting of the content area for the tabbed pane. Once this new bug is filed and dealt with we will take into account these issues and decide upon which behavior will be default. ###@###.### 2002-05-28 The developer's view of the setOpaque() method is incorrect. setOpaque(false) does not and has never meant to set the component to be transparent (although this is a common misconception). Non-opaque components guarantee NOTHING about what pixels they paint. You can read all about the correct meaning of opacity here: http://java.sun.com/products/jfc/tsc/articles/swing2d/index.html#CUSTOM_PAINTING JTabbedPane does NOT break any opacity rules. That all being said, it would be nice to provide a way to turn off the content area painting of JTabbedPane, or to be more backwards compatible. Therefore, I'm leaving this bug open for more investigation. ###@###.### 2003-09-05
05-09-2003