Formatted Text Field put text on top left corner in vision

Hi Guys,

Hope I can get your help.

It is possible to put text in the top left corner of the formatted text field. Currently, I’m using the vision modules so it is possible to do that?

Thanks in advance

The FormattedTextField inherits from the JFormattedTextfield and JTextField classes. Consequently, it doesn't word wrap, and it doesn't have any vertical alignment methods. Expanding it to a height that is greater than one row of text only creates the illusion of a textArea. While it is probably possible to mess with the UI/Layout in some way to create the effect you are after, the end result would still only be the illusion of a text area.

Therefore, I feel that rather than go through all the trouble of forcing the text to vertically align, the simplest approach would be to create the illusion of vertical alignment by nesting a formatted text field into a container with the same background color. The horizontal alignment could be set to LEFT, and textfield could be positioned at the top of the container. Then by simply removing the border of the text field and putting a border around the container, we will have effectively created a text area that doesn't word wrap and has all the features of a FormattedTextField.

Here is a code example that produces effect described effect:

from javax.swing import BorderFactory
formattedTextField = event.source.parent.getComponent('Container').getComponent('Formatted Text Field')
formattedTextField.setHorizontalAlignment(formattedTextField.LEFT)
border = BorderFactory.createEmptyBorder()
formattedTextField.setBorder(border)

Here is the result:
image


Here are the container settings:
image
image

Perhaps you should just use a text area. Hmm?

1 Like

I was curious about the reasons behind this style choice, but I imagined that there must be something that can be done by a formattedTextField that can't be easily done with a text area.