get Window Ancestor - Java Swing

Java examples for Swing:Screen

Description

get Window Ancestor

Demo Code


//package com.java2s;

import java.awt.*;

public class Main {
    public static Window getWindowAncestor(Component c) {
        for (Container p = c.getParent(); p != null; p = p.getParent()) {
            if (p instanceof Window) {
                return (Window) p;
            }//from  www  .  j ava2  s  .  c o  m
        }
        return null;
    }
}

Related Tutorials