JDK-7156657 : Version 7 doesn't support translucent popup menus against a translucent window
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86
  • Submitted: 2012-03-24
  • Updated: 2013-04-22
  • Resolved: 2012-06-12
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 JDK 8
7u6Fixed 8 b43Fixed
Related Reports
Relates :  
Relates :  
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
06-06-2012