How to handle a keystroke event in java, but pass it on so that it has it's "natural" effect?

StackOverflow https://stackoverflow.com/questions/13240132

  •  27-11-2021
  •  | 
  •  

質問

I have this code that makes some action execute when user is in textArea (JTextArea instance) and 'enter' is pressed:

textArea.getInputMap().put(
            KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionMapKey);
    textArea.getActionMap().put(actionMapKey, new AbstractAction() {

        int numLines, lineStart, lineEnd;
        Element lineElem;
        String lineText;

        @Override
        public void actionPerformed(ActionEvent e) {

                         //all the things to be done when enter is pressed
                    }
    });

It works fine, but after the action is handled, no newline appears in the textArea. Is there any way to pass the 'enter' keystroke on so that it actually creates newline?

Thanks

役に立ちましたか?

解決

If I'm not mistaken, you should be able to call the super method you are overloading after all of your custom actions.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top