public static boolean find(JTextArea textArea,String text,boolean forward,boolean matchCase,boolean wholeWord,boolean regex) throws PatternSyntaxException {
  Caret c=textArea.getCaret();
  int start=forward ? Math.max(c.getDot(),c.getMark()) : Math.min(c.getDot(),c.getMark());
  String findIn=getFindInText(textArea,start,forward);
  if (findIn == null || findIn.length() == 0)   return false;
  if (regex == false) {
    int pos=getNextMatchPos(text,findIn,forward,matchCase,wholeWord);
    findIn=null;
    if (pos != -1) {
      c.setSelectionVisible(true);
      pos=forward ? start + pos : pos;
      selectAndPossiblyCenter(textArea,pos,pos + text.length());
      return true;
    }
  }
 else {
    Point regExPos=getNextMatchPosRegEx(text,findIn,forward,matchCase,wholeWord);
    findIn=null;
    if (regExPos != null) {
      c.setSelectionVisible(true);
      if (forward) {
        regExPos.translate(start,start);
      }
      selectAndPossiblyCenter(textArea,regExPos.x,regExPos.y);
      return true;
    }
  }
  return false;
}

public static boolean find ( JTextArea textArea , String text , boolean forward , boolean matchCase , boolean wholeWord , boolean regex ) throws PatternSyntaxException { Caret c = textArea . getCaret ( ) ; int start = forward ? Math . max ( c . getDot ( ) , c . getMark ( ) ) : Math . min ( c . getDot ( ) , c . getMark ( ) ) ; String findIn = getFindInText ( textArea , start , forward ) ; if ( findIn == null || findIn . length ( ) == 0 ) return false ; if ( regex == false ) { int pos = getNextMatchPos ( text , findIn , forward , matchCase , wholeWord ) ; findIn = null ; if ( pos != - 1 ) { c . setSelectionVisible ( true ) ; pos = forward ? start + pos : pos ; selectAndPossiblyCenter ( textArea , pos , pos + text . length ( ) ) ; return true ; } } else { Point regExPos = getNextMatchPosRegEx ( text , findIn , forward , matchCase , wholeWord ) ; findIn = null ; if ( regExPos != null ) { c . setSelectionVisible ( true ) ; if ( forward ) { regExPos . translate ( start , start ) ; } selectAndPossiblyCenter ( textArea , regExPos . x , regExPos . y ) ; return true ; } } return false ; }
finds the next instance of the string / regular expression specified from the caret position . if a match is found , it is selected in this text area .
