Not finding text because it is case sensitive
I am having problem with my highlights method. I want to search a text area with the pattern entered in the text field. At the moment, it is case sensitive and correctly find the pattern if the case are the same. How can I make it find the pattern when the case are different?
For example:
Text Area:- I love PrograMMing in Java
Pattern to find:- programming
It does not successfully find programming because programming in text area is written as: PrograMMing.
// Creates highlights around all occurrences of pattern in log
publicvoid highlight(JTextComponent textComp, String pattern){
try{
Highlighter hilite = textComp.getHighlighter();
Document doc = textComp.getDocument();
String text = doc.getText(0, doc.getLength());
int pos = 0;
boolean foundAnyText =false;
// Search for pattern
while ((pos = text.indexOf(pattern, pos)) >= 0){
// Create highlighter using private painter and apply around pattern
hilite.addHighlight( pos, pos + pattern.length(), myHighlightPainter );
pos += pattern.length();
foundAnyText =true;
}
if(!foundAnyText){
JOptionPane.showMessageDialog( null,"Text not found." );
}
}catch (BadLocationException e){
System.out.println("BadLocationException: " + e.getMessage() );
}
}

