Changing Border Color of AWT TextField

tiger picture tiger · Sep 28, 2011 · Viewed 22.5k times · Source

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?

Answer

Barend picture Barend · Sep 28, 2011

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.