How to stop cursor from moving to a new line in a TextArea when Enter is pressed
问题 I have a Chat application. I'd like the cursor in the chatTextArea to get back to the position 0 of the TextArea chatTextArea . This, however, won't work: chatTextArea.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { ChatClient.main(new String[]{"localhost", String.valueOf(4444), chatTextArea.getText()}); chatTextArea.setText(""); chatTextArea.positionCaret(0); } } }); How can I get it to work? Thank you. 回答1: