Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7156657

Version 7 doesn't support translucent popup menus against a translucent window

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b43
    • CPU:
      x86
    • OS:
      windows_7

      Backports

        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 ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rupashka Pavel Porvatov (Inactive)
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: