Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JTextField changing border

How can I change the border color of JTextField? I tried someField.setBorder(new LineBorder(Color.RED,2)), but it is giving me

mismatcherror(incompatible types: javafx.scene.paint.Color can not be converted to java.awt.Color).

Thanks for answers in advance.

like image 466
user10284173 Avatar asked May 17 '26 01:05

user10284173


1 Answers

Please check your import section. You should import java.awt.Color like this:

import java.awt.Color;

If you want to create borders with the LineBorder class, then you can do:

import java.awt.Color;
import javax.swing.border.LineBorder;

textField.setBorder(new LineBorder(Color.RED, 2));

Another option is to create borders with the BorderFactory class, like this:

import java.awt.Color;
import javax.swing.BorderFactory;

textField.setBorder(BorderFactory.createLineBorder(Color.RED, 2));
like image 94
HugoTeixeira Avatar answered May 19 '26 14:05

HugoTeixeira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!