Java Swing JtextField inset

一个人想着一个人 提交于 2019-12-10 13:58:20

问题


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

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


回答1:


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);
textField.setBorder(rounded);
Border border = new CompoundBorder(rounded, empty);

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.




回答2:


setMargin(Inset myInset) worked for me:

import java.awt.Insets;
import javax.swing.*;

public class TextFieldFun {
   public static void main(String[] args) {
      JTextField textfield = new JTextField(20);
      JPanel panel = new JPanel();
      panel.add(textfield);

      textfield.setMargin(new Insets(0, 10, 0, 0));

      JOptionPane.showMessageDialog(null, panel);
   }
}


来源:https://stackoverflow.com/questions/8305460/java-swing-jtextfield-inset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!