Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Go to new line when Shift+Enter is pressed in text area

941623Jun 7 2012 — edited Jun 8 2012
Hi, I would like to know how to go to a new line in a text area when a key combination of Shift+Enter is pressed. (Pressing enter itself causes the text to be cleared and sent off to an ObservableList). Here's what I was trying:
 text.setOnKeyReleased(new EventHandler<KeyEvent>() {
        final KeyCombination comb1 = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.SHIFT_DOWN);
        final KeyCombination comb2 = new KeyCodeCombination(KeyCode.ENTER);

         public void handle(KeyEvent t) {
                if (comb2.match(t) && !comb1.match(t)) {
                        obs.addAll(text.getText());
                        text.clear();
        }
    }
}); 
I'm not aware of any explicit function which allows the caret position to position itself to a new line.
This post has been answered by shakir.gusaroff on Jun 7 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 6 2012
Added on Jun 7 2012
7 comments
394 views