-
Bug
-
Resolution: Duplicate
-
P3
-
7u10
-
os_x
FULL PRODUCT VERSION :
java version " 1.7.0_12-ea "
Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b02)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b25, mixed mode)
AND
java version " 1.7.0_10-ea "
Java(TM) SE Runtime Environment (build 1.7.0_10-ea-b16)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
OS X 10.8.2
A DESCRIPTION OF THE PROBLEM :
JMenuItems still fire twice when used with the ScreenMenuBar and when they use shift-cmd or alt-cmd modifiers. They fire only once when the only modifier is cmd.
I was verifying that bug 7160951 was actually fixed when I noticed that it still fired twice for more complicated modifiers. There are also times when it only fires once with shift-cmd and alt-cmd but most often it fires twice.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test frame and try both key shortcuts.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output shows that the action listener fires twice for each key press.
ACTUAL -
There should only be one line of output per key press.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
public class TestFrame extends JFrame {
public TestFrame() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu( " File " );
JMenuItem shiftItem = new JMenuItem( " Shift " );
shiftItem.setAccelerator(KeyStroke.getKeyStroke('O',
KeyEvent.SHIFT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
shiftItem.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
System.out.println( " Shift was called " );
}
});
fileMenu.add(shiftItem);
JMenuItem altItem = new JMenuItem( " Alt " );
altItem.setAccelerator(KeyStroke.getKeyStroke('O',
KeyEvent.ALT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
altItem.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
System.out.println( " Alt was called " );
}
});
fileMenu.add(altItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
pack();
setVisible(true);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
System.setProperty( " apple.laf.useScreenMenuBar " , " true " );
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
new TestFrame();
}
});
}
}
---------- END SOURCE ----------
java version " 1.7.0_12-ea "
Java(TM) SE Runtime Environment (build 1.7.0_12-ea-b02)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b25, mixed mode)
AND
java version " 1.7.0_10-ea "
Java(TM) SE Runtime Environment (build 1.7.0_10-ea-b16)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
OS X 10.8.2
A DESCRIPTION OF THE PROBLEM :
JMenuItems still fire twice when used with the ScreenMenuBar and when they use shift-cmd or alt-cmd modifiers. They fire only once when the only modifier is cmd.
I was verifying that bug 7160951 was actually fixed when I noticed that it still fired twice for more complicated modifiers. There are also times when it only fires once with shift-cmd and alt-cmd but most often it fires twice.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test frame and try both key shortcuts.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output shows that the action listener fires twice for each key press.
ACTUAL -
There should only be one line of output per key press.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
public class TestFrame extends JFrame {
public TestFrame() {
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu( " File " );
JMenuItem shiftItem = new JMenuItem( " Shift " );
shiftItem.setAccelerator(KeyStroke.getKeyStroke('O',
KeyEvent.SHIFT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
shiftItem.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
System.out.println( " Shift was called " );
}
});
fileMenu.add(shiftItem);
JMenuItem altItem = new JMenuItem( " Alt " );
altItem.setAccelerator(KeyStroke.getKeyStroke('O',
KeyEvent.ALT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
altItem.addActionListener(new ActionListener() {
@Override public void actionPerformed(ActionEvent e) {
System.out.println( " Alt was called " );
}
});
fileMenu.add(altItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
pack();
setVisible(true);
}
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
System.setProperty( " apple.laf.useScreenMenuBar " , " true " );
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
new TestFrame();
}
});
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8002114 fix failed for JDK-7160951: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
-
- Closed
-