Skip to content
Advertisement

Java Swing JtextField inset

I am working with Netbeans GUI and I would like to add 3 pixels of space at the beginning of my jTextField :

enter image description here

I have tryied with setMargin, setInset in the GUI but it doesn’t change anything.

I have another question, why the bottom right border is not rounded ? here is my code :

Border roundedBorder = new LineBorder(new Color(210,210,210), 1, true);
researchTextField.setBorder(roundedBorder);

thank you very much,

Regards

Advertisement

Answer

Using setMargin(...) should work.

However, if you are also using a Border then that may be the problem.

Try using a CompoundBorder where the inner border is an EmptyBorder() and the outer border is your other border. For example:

Border rounded = new LineBorder(new Color(210,210,210), 1, true);
Border empty = new EmptyBorder(0, 3, 0, 0);
Border border = new CompoundBorder(rounded, empty);
textField.setBorder(border);

Read the section from the Swing tutorial on How to Use Borders for more information and examples.

why the bottom right border is not rounded ?

I’m not sure why your bottom/right is not rounded. Using the Metal LAF on XP the right borders (top and bottom) appear rounded but the left borders are not rounded. When I use a border size of 2 or more all corners appear equally rounded.

Advertisement