Jtextfield left alignment, but he won’t stay left

Asked

Viewed 77 times

0

I’m working with Jtextfield and I’m having a problem with alignment.

The field size is standard, I can’t change it. The field is also not editable, it receives the value based on a calculation between quantity and Unit value. It gets a very large cash value, 15 digits and really needs to be this size for tax purposes. The problem is that even though he is aligned to the Left, when he receives the number, he does not show the initial numbers but the end ones.. for example:

inserir a descrição da imagem aqui

and he should stay like this:

inserir a descrição da imagem aqui

I’ve used the setHorizontalAlignment(JTextField.LEFT); and he remains in the same situation.

Would anyone have any idea?

1 answer

1


Friend, this position has no relation with the alignment of the text since its text is bigger than the JTextField, but by the position of the cursor.
To display the beginning of the text and not the end as this happening, use:

jTextField.setCaretPosition(0);

Important
You must use the above command afterward to set the text in Jtextfield, so that it moves the cursor from this field to the first position.

  • Thanks, I was using this caretPosition, but when creating Textfield and not when it is updated. It worked now!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.