Howdy, Stranger!

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

Categories

unbind predefined accelerator keys?

KyonKyon Member Posts: 113
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

  • KyonKyon Member Posts: 113
    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 --

  • Shawn CarterShawn Carter Member Posts: 0

    _______ { http://forcoder.org } free video tutorials and ebooks about / Perl Visual Basic PL/SQL C++ R Ruby Assembly Swift Objective-C Java Python PHP MATLAB Go Scratch C JavaScript C# Visual Basic .NET Delphi Kotlin Clojure Apex Ada Prolog ABAP ML LabVIEW Hack Scala Lua Bash Lisp VBScript Logo D COBOL Alice Rust FoxPro Crystal F# Dart Scheme Julia Transact-SQL Awk Erlang Fortran SAS / ________

Sign In or Register to comment.