Note that there are some explanatory texts on larger screens.

plurals
  1. POJMenuItem accelerator not working after showing two non-modal JDialogs? (Mac only?)
    primarykey
    data
    text
    <p>I have the problem that the accelerators of JMenuItems aren't working anymore after showing two JDialogs directly after one another.</p> <p>Please take a look at this small example that reproduces the problem:</p> <pre><code>import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DialogBug { public static void main(String[] args) { SwingUtilities.invokeLater(new StartupRunnable(args.length == 0)); } public static class StartupRunnable implements Runnable { private boolean both; public StartupRunnable(boolean both) { this.both=both; } public void run() { MyFrame myFrame=new MyFrame(); myFrame.setVisible(true); myFrame.startUp(both); } } public static class MyFrame extends JFrame { private MyDialog dialog1; private MyDialog dialog2; public MyFrame() { super("MyFrame"); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); initUI(); } private void initUI() { dialog1=new MyDialog(this); dialog2=new MyDialog(this); JMenuBar menuBar=new JMenuBar(); JMenu fileMenu=new JMenu("File"); menuBar.add(fileMenu); fileMenu.add(new JMenuItem(new OpenAction())); setJMenuBar(menuBar); setSize(200,200); } public void startUp(boolean both) { dialog1.setVisible(true); if(both) { dialog2.setVisible(true); } } private class OpenAction extends AbstractAction { public OpenAction() { super("Open"); KeyStroke accelerator = KeyStroke.getKeyStroke("ctrl O"); putValue(Action.ACCELERATOR_KEY, accelerator); } public void actionPerformed(ActionEvent e) { System.out.println("Open executed"); } } } public static class MyDialog extends JDialog { public MyDialog(JFrame parent) { super(parent); setTitle("Dialog"); setModal(false); add(new JButton(new OkAction())); pack(); } private class OkAction extends AbstractAction { public OkAction() { super("Ok"); } public void actionPerformed(ActionEvent e) { setVisible(false); } } } } </code></pre> <p>Compile it using <code>javac DialogBug.java</code> and execute it running <code>java DialogBug</code>.</p> <p>You'll see two with "Ok"-Buttons. Dismiss both dialogs clicking them. Now press "Ctrl-O". This should print "Open executed" to the console but this won't happen. Now click the "File" menu. Now "Ctrl-O" will work as expected.</p> <p>If you start the app with any argument, e.g. <code>java DialogBug x</code> then only one dialog will open and "Ctrl-O" will work immediately after dismissing the dialog, as expected.</p> <p>My environment is the following:</p> <pre><code>java version "1.6.0_15" Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219) Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode) </code></pre> <p>But as far as I know this app behaves similar in other VMs.</p> <p>Please help me!<br> I really don't have any idea what might go wrong here. If this is a Java bug (and I expect it to be one) then please let me know if you have a workaround...</p> <p>If you can or can't reproduce this on other systems please tell me so in the comments.<br> Thanks a lot!</p> <p><strong>Update</strong><br> After <a href="http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard" rel="nofollow noreferrer">installing Java 1.5 on Snow Leopard</a> (<em>sigh</em>) I can confirm that this happens with 1.5.0_19, too, at least on Snow Leopard.</p> <p><strong>Update 2</strong><br> Works for me on Windows XP.</p> <pre><code>java version "1.6.0_13" Java(TM) SE Runtime Environment (build 1.6.0_13-b03) Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing) java version "1.5.0_13" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05) Java HotSpot(TM) Client VM (build 1.5.0_13-b05, mixed mode) </code></pre> <p><strong>Update 3</strong><br> Seems to work on Windows Vista, too. This makes this a Mac OS X 10.5+10.6 issue, AFAIK so far.</p> <p><strong>Update 4</strong><br> This bug is filed under Problem ID #7240026 at Apple.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload