Java tutorial
//package com.java2s; import javax.swing.*; import java.awt.*; public class Main { public static JViewport getViewportAncestor(Component c) { for (Container p = c.getParent(); p != null; p = p.getParent()) { if (p instanceof JViewport) { return (JViewport) p; } } return null; } }