unbind predefined accelerator keys?

Hi.

I've got a little problem with accelerator keys. I've got an JApplet with a standard edit menu containing menu items like cut, copy & paste.
Concerning the paste action I've defined a class CustomPasteAction which does some extra checking before pasting the currently copied (or cut) text.
[code]
JMenuItem jmiPaste = new JMenuItem(new CustomPasteAction());
jmiPaste.setText(langResources.getString("Paste"));
...
jmEdit.add(jmiPaste);
[/code]

In addition I've defined a keyboard shortcut for Ctrl+V to invoke that action with:
[code]
jmiPaste.setAccelerator(KeyStroke.getKeyStroke('V', java.awt.Event.CTRL_MASK, false));
[/code]

The problem I got is that when I use the keyboard shortcuts, another paste action than the one I registered for that shortcut is invoked. When I use the menu-entries themselves (slow working by clicking Edit > Paste) - my CustomPasteAction gets invoked.

Does anybody have an idea why's that and how I can disable the preregistered paste actions (if there are any)?

I'm really stuck with that for some time now. Any help is greatly appreciated.

Cheers,
Kyon

-- planning is the substitution of hazard by error --

Comments

  • Hi again.

    I found out how to do this. I just logged the keys (I was already implementing KeyListener) and caught the case when the paste should happen:
    [code]
    public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();
    ...
    if ((keyCode == KeyEvent.VK_V) && (e.isControlDown())) {
    // invoke my own action and discard the event before it gets handled
    // the default way:
    new CustomPasteAction().actionPerformed(new ActionEvent(..));
    e.consume();
    }
    ...
    }
    [/code]

    Thanks all the same to those who spent time on this.

    Cheers,
    Kyon

    -- planning is the substitution of hazard by error --

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion