I am creating a small application. I have 2 JTextFields. When compile 2 sentence between 2 jTextFields I want to show the error word in red color in 2nd jTextFiled. I have create a small code but it is showing whole sentence as in red. (For example I have a sentence like "abcd efgh ijkl". If I re-enter the word in jTextField as "abcd egfh lkjl" I want to show only error words in red color).
My code is as follows:
private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(jTextField1.getText().trim().equals(jTextField2.getText().trim()))
{
jTextField2.setForeground(Color.green);
}
else
{
jTextField2.setForeground(Color.red);
}
}