United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7156657 Version 7 doesn't support translucent popup menus against a translucent window
JDK-7156657 : Version 7 doesn't support translucent popup menus against a translucent window

Details
Type:
Bug
Submit Date:
2012-03-24
Status:
Resolved
Updated Date:
2013-04-22
Project Name:
JDK
Resolved Date:
2012-06-12
Component:
client-libs
OS:
windows_7
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
A DESCRIPTION OF THE REQUEST :
Under version 6, popup menus could be translucent, even against a transparent/translucent window.  Under 7u3 the popup becomes opaque when its parent window is non-opaque.

JUSTIFICATION :
Consistency with previous versions (6u31), and it can make for a nice visual effect.  My application becomes "broken" because it offers the option for menu translucency.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Popups against a non-opaque window should be allowed to be translucent.
ACTUAL -
Popups against a non-opaque window can't be translucent.  Here's a screenshot showing the difference between 6u31 and 7u3:

http://globalisk.com/java/JDK6v7.png


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

public class TranslucentPopup {
    
    public static void main( String[] args ) {
        JMenu fileMenu = new JMenu( "File" );
        fileMenu.getPopupMenu().setUI( new TranslucentPopupMenuUI() );
        fileMenu.add( new JTranslucentMenuItem( "One" ) );
        fileMenu.add( new JTranslucentMenuItem( "Two" ) );
        fileMenu.add( new JTranslucentMenuItem( "Three" ) );
        JFrame frame = new JFrame( "Test transclucent menus" );
        frame.setUndecorated( true );
        com.sun.awt.AWTUtilities.setWindowOpaque( frame, false );
        JMenuBar mb = new JMenuBar();
        mb.add( fileMenu );
        frame.setLayout( new BorderLayout() );
        frame.add( mb, BorderLayout.NORTH );
        JPanel pan = new JPanel( new BorderLayout() );
        pan.setBackground( new Color( 224, 174, 174, 174 ) );
        frame.add( pan, BorderLayout.CENTER );
        frame.pack();
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.setSize( 300, 300 );
        frame.setLocation( 400, 250 );
        frame.setVisible( true );
    }
    
    static class JTranslucentMenuItem extends JMenuItem {
        public JTranslucentMenuItem( String label ) {
            super( label );
            setOpaque( false );
        }
    }

    static class TranslucentPopupMenuUI extends BasicPopupMenuUI {

        public static TranslucentPopupMenuUI createUI( JComponent c ) {
            c.setOpaque( false );
            return new TranslucentPopupMenuUI();
        }

        @Override public void installUI( JComponent c ) {
            super.installUI( c );
            c.setOpaque( false );
        }

        @Override public void paint( Graphics g, JComponent c ) {
            Graphics2D g2 = (Graphics2D)g;
            g2.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.25f ) );
            g2.setColor( Color.BLACK );
            g2.fillRect( 0, 0, c.getWidth(), c.getHeight() );
            g2.setComposite( AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 1.0f ) );
            g2.drawRect( 0, 0, c.getWidth() - 1, c.getHeight() - 1 );
        }
    }
}

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

                                    

Comments
EVALUATION

The fix of CR 7027486 (JPopupMenu doesn't take window shape into account) doesn't take into account that some users use translucent windows with translucent menus. After discussions the following decision was made:
1. When JPopupMenu#setLightWeightPopupEnabled is set to false HEAVY_WEIGHT popups is used (instead of MEDIUM_WEIGHT). This fix was done in CR 6800513 (GTK-LaF renders menus incompletely) and that allows to use non-translucent and non-clipped popups for translucent or shaped windows
2. Fix of CR 7027486 should be reverted
3. The TransparentRuler should be corrected according new fix
                                     
2012-06-06



Hardware and Software, Engineered to Work Together