Here is code to have the TextArea control in Java FX move to the next control when the TAB key is pressed.

Somtimes we do not want tabs inside our TextArea control. Hence, when the TAB key is pressed, its natural action should be to move focus to the next available control.

If CONTROL+TAB is pressed and the TextArea control has focus, a TAB character will be inserted within the control.

I wish Oracle simply included this feature so developers would not have to code it from scratch. However, I came across a custom made class called ScrollFreeTextArea from the javafx-demos website.

This class simply did the trick for me. So whenever you type a long text and it wraps itself or press the ENTER key for a new line, the height of the TextArea increases without displaying the scrollbar.

Here is the complete source code.

You may want yo create something like this.

textarea-titled-border

Now, even using CSS this is not possible if you directly add a label on the TextArea itself and change its z-location. I came across a post somewhere in the Stack Overflow forum and user jewelsea created a custom made BorderedTitledPane class that simulates a Titled Border in Java’s Swing.

Using this class I added a TextArea to the BorderedTitledPane and with a little CSS tweaking, removed the border and changed its z-location so that the Label title will be positioned right between the border of the TextArea.

Here is the BorderedTitlePane.

And here is the CSS code to make that possible.

Doing this in Swing is possibly tedious but Java FX and CSS gives developers so much flexibility creating new layouts.

To use the class, call it like this.

And add it to the scene’s container.

Related Posts Plugin for WordPress, Blogger...