static JScrollPane enclosingScrollPane(Component c) { while (c.getParent() != null && && !(c.getParent() instanceof JViewport) && c.getParent().getComponentCount() == 1) c = c.getParent(); // for jscroll_center if (!(c.getParent() instanceof JViewport)) null; c = c.getParent().getParent(); ret c instanceof JScrollPane ? (JScrollPane) c : null; }