Changing Border Color of AWT TextField
tf.setBorder(new LineBorder(Color.red,1));
//new LineBorder(color,width);
The AWT TextField
does not support borders, as you've found. You could emulate a border by putting the text field inside a Panel
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 than JPanel
or JLabel
, we recommend that you put the component in a JPanel
and set the border on the JPanel
."
Addendum: While this suggests an approach, it is irrelevant to a pure AWT application.