Component (@NotNull List<? extends Component> components, int start, int direction) { for (int i = start; i >= 0 && i < components.size(); i += direction) { Component c = components.get(i); if (c != null && c.isShowing()) return c; } return null; }