private void doSearch(boolean forward) {

		if (!nextButton.isEnabled()) {
			return;  // don't search while disabled
		}

		clearStatusText();
		boolean useRegex = regexRadioButton.isSelected();
		String searchText = comboBox.getText();

		CursorPosition cursorPosition = searcher.getCursorPosition();
		SearchLocation searchLocation =
			searcher.search(searchText, cursorPosition, forward, useRegex);

		//
		// First, just search in the current direction.
		//
		if (searchLocation != null) {
			notifySearchHit(searchLocation);
			return;
		}

		//
		// Did not find the text in the current direction.  Wrap and try one more time.
		//
		String wrapMessage;
		if (forward) {
			wrapMessage = "Reached the bottom, continued from top";
			cursorPosition = searcher.getStart();
		}
		else {
			wrapMessage = "Reached the top, continued from the bottom";
			cursorPosition = searcher.getEnd();
		}

		searchLocation = searcher.search(searchText, cursorPosition, forward, useRegex);
		if (searchLocation != null) {
			notifySearchHit(searchLocation);
			notifyUser(wrapMessage);
			return;
		}

		//
		// At this point, we wrapped our search and did *not* find a match.  This can only
		// happen if there is no matching text anywhere in the document, as after wrapping
		// we will again find the previous match, if it exists.
		//
		notifyUser("Not found");
	}
A dialog used to perform text searches on a text display.
Ghidra/Framework/Docking/src/main/java/docking/widgets/FindDialog.java