Here you can find the source of preventInputingNewLineOnTextArea(JTextArea txe, AbstractAction actionOnEnter)
public static void preventInputingNewLineOnTextArea(JTextArea txe, AbstractAction actionOnEnter)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.event.*; public class Main { public static void preventInputingNewLineOnTextArea(JTextArea txe, AbstractAction actionOnEnter) { if (actionOnEnter == null) { actionOnEnter = new AbstractAction() { @Override/* w ww . j a va 2s . c o m*/ public void actionPerformed(ActionEvent e) { // do nothing } }; } txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), actionOnEnter); txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK), actionOnEnter); txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), actionOnEnter); txe.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.ALT_DOWN_MASK), actionOnEnter); } }