Future<List<Object>> (String pattern) { clearResults(); CompletableFuture<List<Object>> future = new CompletableFuture<>(); SearchAdapter listener = new SearchAdapter() { @Override public void searchFinished(@NotNull List<Object> items) { future.complete(items); SwingUtilities.invokeLater(() -> removeSearchListener(this)); } }; addSearchListener(listener); mySearchField.setText(pattern); return future; }