Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#3 Swallowed Ctrl-keys?

open
nobody
None
5
2004-03-05
2004-03-05
PhilipM
No

Ji,
I have added the jEdit package to my app something like
this:

class EditComponent extends JEditTextArea implements
PropertyChangeListener
{
///my class contents
}

///in main
JFrame frame=new JFrame("xxxx");
EditComponent edit=new EditComponent(data);
EditMenubar menu=new EditMenubar(frame,edit);
frame.setJMenuBar(menu);
frame.getContentPane().add(edit);

My app has a menubar, and some of the menu options
have accelerators attached (e.g. Ctrl-o for open).
It looks like they are being swallowed by JEditTextArea.
If I replace JEditTextArea with JEditorPane, then the
accelerators work fine.

Any ideas?
,Philip

Discussion

  • Pascal Richter
    Pascal Richter
    2004-08-17

    Logged In: YES
    user_id=821473

    I had the same problem and found the problem.
    Class JEditTextArea, method processKeyEvent: The key event
    will not be processed because it is directly forwarded to
    the (internal) input handler of the jeditTextArea (for
    perfomance reasons). I added the line:
    super.processKeyEvent(evt);
    to the end of the method, to let the super class process the
    KeyEvent too. It works!!

    Here is the whole method:
    <code>
    public void processKeyEvent(KeyEvent evt)
    {
    if(inputHandler == null)
    return;
    switch(evt.getID())
    {
    case KeyEvent.KEY_TYPED:
    inputHandler.keyTyped(evt);
    break;
    case KeyEvent.KEY_PRESSED:
    inputHandler.keyPressed(evt);
    break;
    case KeyEvent.KEY_RELEASED:
    inputHandler.keyReleased(evt);
    break;
    }

    super.processKeyEvent(evt); // <--- add this line
    }
    </code>

    ps: sorry for my bad english