Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6687960
Votes 0
Synopsis Background of component invisible with Nimbus
Category java:classes_swing
Reported Against
Release Fixed 6u10(b26)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs 6693233
Submit Date 14-APR-2008
Description
FULL PRODUCT VERSION :
1.6.0_10

ADDITIONAL OS VERSION INFORMATION :
ver XP

A DESCRIPTION OF THE PROBLEM :
When I have e.g. a JEditorPane on a JPanel and set:
myEditorPane.setOpaque(false)
I will only see a white background, not the panel behind the editorpane.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Only create a panel with a certain background and place a JEditorPane on it. Set the editorpane to opaque(false) and have a look, if you see the panels color.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to see the color of the panel behind.
ACTUAL -
I only see a white field.

REPRODUCIBILITY :
This bug can be reproduced always.
Posted Date : 2008-04-14 08:14:36.0
Work Around
N/A
Evaluation
It works with the Metal LaF, assigned to the Nimbus owner

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

public class bug6687960 {

    private static void createGui() {
        final JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel panel = new JPanel(new BorderLayout());
        panel.setBackground(Color.red);
        frame.add(panel);

        JEditorPane pane = new JEditorPane();
        pane.setOpaque(false);

        panel.add(pane);
        
        frame.setSize(200, 200);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                bug6687960.createGui();
            }
        });
    }
}
Posted Date : 2008-04-14 18:03:54.0

This is a problem the the orginal design of Swing and how it has been confusing for years. The issue is setOpaque(false) has had a side effect in exiting LAFs which is that of hiding the background which is not really what it is ment for. It is ment to say that the component my have transparent parts and swing should paint the parent component behind it. Nimbus is the first Sun LAF to need transparency in components for rounded corners and outer glow focus. This means that in Nimbus most of the standard components are non-opaque by default. So setting them to non-opaque has no effect. JButton is nice that it has a setContentAreaPainted() method that can be used to turn off background painting but unfortunatly there has been no option for this with other Nimbus components such as JTextField. One workaround has been to set the background color to transparent like new Color(0,0,0,0). We have decided for this issue to make a color which is 100% transparent (eg, Alpha == 0) mean that the background will not be painted at all.

So the solution for this bugs requirement is:

	textField.setBorder(BorderFactory.createEmptyBorder());
	textField.setBackground(new Color(0,0,0,0));

Which will give you a textfield with no border or background.
Posted Date : 2008-05-29 22:42:37.0
Comments
  
  Include a link with my name & email   

Submitted On 17-JUN-2008
bjarne77
I'm experiencing the same problem, but it is not fixed when using the solution provided. I cannot set the JTextPane background to a transparent value. It keeps showing the background control color. Also with a text/html setting and a stylesheet rule background:none;  the background is not transparent to the underlying component. Is this something that is still being worked at?

Thanks in advance,
Richard



PLEASE NOTE: JDK6 is formerly known as Project Mustang