Java GUI助记符(R)激活 弹出无关应用,用助记符(X)效果正常。

代码如下


package test;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MnemonicTest {
    public static void main(String[] args) {
        new MyDialog("对话框例子");
    }
}

class MyDialog extends JDialog implements ActionListener {
    MyDialog(String text) {
        super();
        setTitle(text);
        init();
    }

    private void init() {
        setLayout(null);
        setSize(600, 400);
        setLocationRelativeTo(null);
        setResizable(false);
        setVisible(true);
        JButton button = new JButton("按键(R)");
        button.setMnemonic('R');
        button.addActionListener(this);
        button.setBounds(200, 100, 80, 40);
        getContentPane().add(button);
        show();
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        Color cyan = Color.cyan;
        getContentPane().setBackground(cyan);
    }
}

怎么在助记符激活时屏蔽其他应用的快捷键?

居然还有用这写界面的。。。。。