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

[macosx] Key Bindings break with awt GraphicsEnvironment setFullScreenWindow

XMLWordPrintable

    • b115
    • os_x

        FULL PRODUCT VERSION :
        The code is functional with the version of Java included with the current version of Netbeans.
        java version " 1.6.0_37 "
        Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-11M3909)
        JAva HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)

        The bug occurs with the most recent version of Java SE JDK for Mac OSX as of 1/16/2013 which I have uninstalled.
        The install file that has the bug is: jdk-7u11-macosx-x64.dmg

        The code is functional on Windows 7 64 Ultimate using both versions. My windows java version is:
        java version " 1.7.0.09 "
        java(TM) SE Runtime Environment (build 1.7.0.09-b05)
        Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)


        ADDITIONAL OS VERSION INFORMATION :
        Mac OS X 10.7.5
        This bug has been reproduced on 3 different mac systems though I am unsure of the other OS version numbers.

        A DESCRIPTION OF THE PROBLEM :
        Installing the current version of JDK causes key bindings to stop working in awt GraphicsEnvironment class using setFullScreenWindow method. I'm not sure if this is caused by an inability to focus on the fullscreen window, but I have tried all of the JComponent focus varients:
        WHEN_FOCUSED
        WHEN_IN_FOCUSED_WINDOW
        WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

        I have also tried setExtendedState.


        REGRESSION. Last worked in version 6u31

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run code on JDK 6 on Mac OSX and it will work.
        Install most recent JDK (7) on Mac OSX and it will not work.
        Remove JDK 7 and run code on JDK 6 and it will work again.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Running the code should put up a blank gray screen in fullscreen mode. Pressing ENTER should cause the program to output " Enter was pressed. " to stdout. Pressing ESCAPE should cause the program to output " Program Terminated by ESC Key " and close.
        ACTUAL -
        The ENTER and ESCAPE keys do nothing.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        There is no error message associated with this problem.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.*;

        public class FullScreen extends JFrame
        {
            /*
             * screenImage is never set in this code. It can be set to any image
             * the error will still be present. Images have been omitted to simplify
             * the example case.
             */
            private Image screenImage;
            private int width;
            private int height;

            //Create panel for displaying images using paintComponent()
            private PaintPanel mainImagePanel;

            //Used for keybinding
            private Action enterAction;
            private Action escapeAction;
            private static final String enter = " ENTER " ;
            private static final String escape = " ESCAPE " ;

            public FullScreen()
            {
         /**********************************************
          ******THE BELOW LINES CAUSE THE ERROR*********
          **********************************************/

                /******************************************
                 * Removes window framing and sets fullscreen mode.
                 ******************************************/
                
                this.setUndecorated(true);
                GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);

         /**********************************************
          ******THE ABOVE LINES CAUSE THE ERROR*********
          **********************************************/

                width = this.getWidth();
                height = this.getHeight();
                
                //Create panel so that I can use key binding which requires JComponent
                mainImagePanel = new PaintPanel();
                add(mainImagePanel);

                /******************************************
                 * Key Binding
                 ******************************************/

                // Key bound AbstractAction items
                enterAction = new EnterAction();
                escapeAction = new EscapeAction();

                // Gets the mainImagePanel InputMap and pairs the key to the action
                mainImagePanel.getInputMap().put(KeyStroke.getKeyStroke(enter), " doEnterAction " );
                mainImagePanel.getInputMap().put(KeyStroke.getKeyStroke(escape), " doEscapeAction " );

                // This line pairs the AbstractAction enterAction to the action " doEnterAction "
                mainImagePanel.getActionMap().put( " doEnterAction " , enterAction);
                mainImagePanel.getActionMap().put( " doEscapeAction " , escapeAction);

                /******************************************
                 * End Key Binding
                 ******************************************/
            }

            //Stretches and displays images in fullscreen window
            private class PaintPanel extends JPanel
            {
                @Override
                public void paintComponent(Graphics g)
                {
                    if(screenImage != null)
                    {
                        super.paintComponent(g);
                        g.drawImage(screenImage, 0, 0, width, height, this);
                    }
                }
            }

            /******************************************
             * User Input
             ******************************************/

            private class EnterAction extends AbstractAction
            {
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    System.out.println( " Enter was pressed. " );
                }
            }

            private class EscapeAction extends AbstractAction
            {
                @Override
                public void actionPerformed(ActionEvent e)
                {
                    System.out.println( " Program Terminated by ESC Key " );
                    System.exit(0);
                }
            }
            
            public static void main(String[] args)
            {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run()
                    {
                        FullScreen show = new FullScreen();
                        show.setVisible(true);
                    }
                });
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Uninstall JDK 7 and use JDK 6 instead.

              leonidr Leonid Romanov (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: