Object (@NotNull String s) { int selectedIndex = getSelectedIndex(); if (selectedIndex < 0) { selectedIndex = 0; } final ListIterator<Object> it = getElementIterator(selectedIndex); final String _s = s.trim(); // search visible nodes at first while (it.hasNext()) { final TreePath element = (TreePath) it.next(); if (myComponent.isVisible(element) && isMatchingElement(element, _s)) return element; } if (selectedIndex > 0 || myCanExpand) { while (it.hasPrevious()) it.previous(); while (it.hasNext() && it.nextIndex() != selectedIndex) { final TreePath element = (TreePath) it.next(); if (myComponent.isVisible(element) && isMatchingElement(element, _s)) return element; } } if (myCanExpand) { while (it.hasNext()) { final TreePath element = (TreePath)it.next(); if (isMatchingElement(element, _s)) return element; } if (selectedIndex > 0) { while (it.hasPrevious()) it.previous(); while (it.hasNext() && it.nextIndex() != selectedIndex) { final TreePath element = (TreePath)it.next(); if (isMatchingElement(element, _s)) return element; } } } return null; }