How To Add A Titled Border On A TextArea In Java FX

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...

Leave a Reply

Your email address will not be published. Required fields are marked *