How to leave only one edge on Jtextfield?

Asked

Viewed 741 times

2

I wonder how to leave only one edge on one JTextField, similar to data entry when logging into Gmail, that is, with a border at the bottom.

1 answer

5


You can create borders with the class MatteBorder as follows:

textField.setBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.BLUE));

The method createMatteBorder allows you to define the thickness of each component edge in addition to the color. Simply enter 0 in all except the third parameter, which is equivalent to the size of the bottom edge.

Take an example:

inserir a descrição da imagem aqui

Of course to get the image effect above, you need to apply the same background color of your screen to JTextField, something like:

textField.setBackground(seuFrame.getBackground());

or

textField.setBackground(painelDoTexField.getBackground());

otherwise, although it only has a visible border, the background will turn white, highlighting the field of the rest of the screen.

  • It worked really well thank you!

  • @Felipemorenoborges :)

Browser other questions tagged

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