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