There are two text input controls (that I know of), TextInput and TextArea.
 TextInput accepts a single line of text, but it is also only a single line
on the screen, with no provision for wrapping text instead of clumsily
horizontally scrolling.  TextArea happily wraps text, but it also accepts
the Enter key to insert newlines into the content.

What I'm looking for is a control that accepts only a single line of input,
but wraps. It should not accept the Enter key, but instead allow that key to
close a dialog. I tried using a TextArea to which I added
a ComponentKeyListener with this override:

public boolean keyTyped(Component component, char character) {
if (character == Keyboard.KeyCode.ENTER) {
close(true);
return true;
}
return false;
}

That only partly works -- it closes the dialog when the Enter key is
pressed, but it also inserts a newline into the TextArea.  I guess that's
the downside of no guaranteed ordering of listeners.  However, even if I
move that logic to the keyPressed method instead, it doesn't help.

Am I missing something?  I can, of course, post-process the input to remove
the newline, but that seems crufty.

(FWIW, the WPF control corresponding to both of these controls, TextBox,
lets me do this by setting attributes AcceptsReturn=False and
TextWrapping="Wrap".)

Reply via email to