Component (Component c) { if (!myUseViewportViewSizes) return c; JScrollPane scrollPane = ObjectUtils.tryCast(c, JScrollPane.class); JViewport viewport = scrollPane == null ? null : scrollPane.getViewport(); Component view = viewport == null ? null : viewport.getView(); return view == null ? c : view; }