void () { final FocusAdapter spotlightRemover = new FocusAdapter() { @Override public void focusLost(FocusEvent e) { final Component comp = e.getOppositeComponent(); if (comp == mySearch.getTextEditor() || comp == myTreeView.getTree()) { return; } mySpotlightPainter.update(null, null, null); } @Override public void focusGained(FocusEvent e) { if (!StringUtil.isEmpty(mySearch.getText())) { mySpotlightPainter.updateNow(); } } }; myTreeView.getTree().addFocusListener(spotlightRemover); mySearch.getTextEditor().addFocusListener(spotlightRemover); }