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