Java tutorial
//package com.java2s; /* * Copyright (C) 2009 Klaus Reimer <k@ailis.de> * See LICENSE.md for licensing information. */ import java.awt.Component; import java.awt.Frame; public class Main { /** * Finds the frame in which the specified component is located. * * @param component * The component. * @return The frame or null if the component is not in a frame. */ public static Frame findFrame(final Component component) { if (component == null || component instanceof Frame) return (Frame) component; return findFrame(component.getParent()); } }