Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Border Color of AWT TextField

In AWT application I need to set border color of TextField.

In JTextField, I know that we do can do the following

JTextField tf = new JTextField();
tf.setBorder(BorderFactory.createLineBorder(Color.decode("#2C6791")));

But setBorder() method is not availiable in awt TextField. Is there any workaround for this problem?

like image 291
tiger Avatar asked Sep 28 '11 11:09

tiger


2 Answers

tf.setBorder(new LineBorder(Color.red,1));
//new LineBorder(color,width);

Because the method is overloaded you can define the Color, and leave the rest to the default. Alternatively, you can define the whole method and choose the Color, line Thickness, and type of corners; rounded or not.

    public LineBorder(Color color) {
        this(color, 1, false);
    }
    public LineBorder(Color color, int thickness)  {
        this(color, thickness, false);
    }
    @ConstructorProperties({"lineColor", "thickness", "roundedCorners"})
    public LineBorder(Color color, int thickness, boolean roundedCorners)  {
        lineColor = color;
        this.thickness = thickness;
        this.roundedCorners = roundedCorners;
    }
like image 176
Randy G. Avatar answered Nov 08 '22 03:11

Randy G.


tf.setBorder(new LineBorder(Color.red,1));
//new LineBorder(color,width);
like image 45
jam_es Avatar answered Nov 08 '22 02:11

jam_es