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?
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.
The AWT
TextField
does not support borders, as you've found. You could emulate a border by putting the text field inside aPanel
that's just slightly larger than the textfield and changing the background color of the panel.For compatibility with look & feel variations, the
setBorder()
API recommends the following: "In general, when you want to set a border on a standard Swing component other thanJPanel
orJLabel
, we recommend that you put the component in aJPanel
and set the border on theJPanel
."Addendum: While this suggests an approach, it is irrelevant to a pure AWT application.