I need to find a word in JTextArea and highlight it, can you help me with this code?
class managerClass implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e) {
String myWord = txt.getText();
Highlighter h = textArea.getHighlighter();
if (e.getSource() == bFind)
{
pattern = Pattern.compile("\\b"+myWord+"\\b");
Matcher matcher = pattern.matcher(myWord);
while( matcher.find() )
{
int start = matcher.start();
int end = matcher.end();
try {
h.addHighlight(start, end, DefaultHighlighter.DefaultPainter);
} catch (BadLocationException e1) {
e1.printStackTrace();
}
}
JOptionPane.showMessageDialog(null,"No Match Found");
}
}