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

[macosx] apple.laf.useScreenMenuBar regression comparing with jdk6

    XMLWordPrintable

Details

    • 7u6
    • b100
    • os_x

    Backports

      Description

        FULL PRODUCT VERSION :
        This is a build of the next workspace
        http://hg.openjdk.java.net/jdk7u/jdk7u40

        denis@/export/wsps/jdk7u40>hg summary
        parent: 691:11147a12bd8c tip
         Added tag jdk7u40-b30 for changeset 1c141e6fde91

        java version " 1.8.0-ea "
        Java(TM) SE Runtime Environment (build 1.8.0-ea-b93)
        Java HotSpot(TM) 64-Bit Server VM (build 25.0-b34, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        OS X 10.8.4 (12E55)

        EXTRA RELEVANT SYSTEM CONFIGURATION :
          Model Name:Mac mini
          Model Identifier:Macmini6,2
          Processor Name:Intel Core i7

        A DESCRIPTION OF THE PROBLEM :
        On Mac OS X a recommended way to set a system mac menu in java is using apple.laf.useScreenMenuBar property.

        https://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html

        The behaviour of the menu in jdk7 is different comparing with jdk6.

        REGRESSION. Last worked in version 6u45

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the next code with jdk7u40 and with jdk 6.

        ===================== SimpleEditor.java =================
        import javax.swing.*;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.InputEvent;
        import java.awt.event.KeyEvent;

        class SimpleEditor extends JFrame {

            private final JTextArea textArea = new JTextArea(60, 30);

            private SimpleEditor() throws HeadlessException {
                super( " Simple editor " );

                System.setProperty( " apple.laf.useScreenMenuBar " , " true " );
                textArea.setText( " First
        Second
        PLACE CARET HERE
        Fourth
        Fifth " );
                textArea.setCaretPosition( " First
        Second
        PLACE " .length());
                add(textArea);
                JMenuBar mb = new JMenuBar();
                JMenu firstMenu = new JMenu( " FirstMenu " );
                JMenuItem menuItem = new JMenuItem( " FirstItem " );

                KeyStroke ctrlShiftUp = KeyStroke.getKeyStroke(KeyEvent.VK_UP,
                        Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                        | InputEvent.SHIFT_MASK);

                menuItem.setAccelerator(ctrlShiftUp);

                menuItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        System.err.println( " Action on menu item " );
                    }
                });

                firstMenu.add(menuItem);

                mb.add(firstMenu);
                setJMenuBar(mb);
                pack();
                setVisible(true);
            }

            public static void main(String[] args) {

                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        new SimpleEditor();

                    }
                });
            }
        }
        ====================================================

        You can use Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() instead of InputEvent.META_MASK the behaviour is the same.

        After the execution a frame with a JTextArea will be shown. The caret will be placed on the third line.

        I have debugged the issue and found out that a message is send to the CMenuItem method by NSApplication. This leads to the extra call of the action.

        0 liblwawt.dylib 0x0000000118321f5e -[CMenuItem handleAction:] + 162
        1 AppKit 0x00007fff8a259959 -[NSApplication sendAction:to:from:] + 342
        2 AppKit 0x00007fff8a38f36c -[NSMenuItem _corePerformAction] + 406
        3 AppKit 0x00007fff8a38f05a -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 133
        4 AppKit 0x00007fff8a38dce0 -[NSMenu performKeyEquivalent:] + 271
        5 AppKit 0x00007fff8a38d1a3 -[NSApplication _handleKeyEquivalent:] + 829
        6 AppKit 0x00007fff8a24a143 -[NSApplication sendEvent:] + 4480
        7 libosxapp.dylib 0x00000001183aa64f -[NSApplicationAWT sendEvent:] + 179
        8 AppKit 0x00007fff8a16021a -[NSApplication run] + 636
        9 libosxapp.dylib 0x00000001183aa537 +[NSApplicationAWT runAWTLoopWithApp:] + 156
        10 liblwawt.dylib 0x0000000118301991 -[AWTStarter starter:] + 873
        11 Foundation 0x00007fff893f15ca __NSThreadPerformPerform + 225
        12 CoreFoundation 0x00007fff8900ab31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
        13 CoreFoundation 0x00007fff8900a455 __CFRunLoopDoSources0 + 245
        14 CoreFoundation 0x00007fff8902d7f5 __CFRunLoopRun + 789
        15 CoreFoundation 0x00007fff8902d0e2 CFRunLoopRunSpecific + 290
        16 java 0x00000001075f7390 CreateExecutionEnvironment + 871
        17 java 0x00000001075f1b3c JLI_Launch + 1952
        18 java 0x00000001075f76f4 main + 108
        19 libdyld.dylib 0x00007fff8d80a7e1 start + 0
        20 ??? 0x0000000000000006 0x0 + 6

        It seems that the problem is not fixed by the next fixes.

        changeset: 6072:e55e4808077a
        user: leonidr
        date: Tue May 14 21:04:32 2013 +0400
        summary: 8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar

        changeset: 5337:33cc14b77bef
        user: leonidr
        date: Wed Sep 12 19:34:26 2012 +0400
        summary: 7160951: ActionListener called twice for JMenuItem using ScreenMenuBar


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        1. Click on the " FirstItem " menu item. " Action on menu item " message will be printed in the error stream.
        2. Press shortcut CMND+SHIFT+UP. Text will be selected from the initial caret position up to the first symbol in the textarea.
        ACTUAL -
        Additionally to the selection an " Action on menu item " message is printed

        1. Click on the " FirstItem " menu item. " Action on menu item " message will be printed in the error stream.
        2. Press shortcut CMND+SHIFT+UP. Text will be selected from the initial caret position up to the first symbol in the textarea.
        3. " Action on menu item " message will be printed in the error stream.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                  Created:
                  Updated:
                  Resolved: