get current JLayeredPane - Java Swing

Java examples for Swing:JLayeredPane

Description

get current JLayeredPane

Demo Code


//package com.java2s;

import java.awt.Component;
import java.awt.Container;

import javax.swing.JApplet;

import javax.swing.JDialog;
import javax.swing.JFrame;

import javax.swing.JLayeredPane;

public class Main {
    /**/*  w w w  .  j  a  v a2s. c o m*/
     * get current layeredPane
     * @param container
     * @return
     */
    public static JLayeredPane getLayeredPane(Container container) {
        JLayeredPane layeredPane = null;
        if (container instanceof JFrame)
            layeredPane = ((JFrame) container).getLayeredPane();
        else if (container instanceof JDialog)
            layeredPane = ((JDialog) container).getLayeredPane();
        else {
            for (int i = 0; i < container.getComponentCount(); i++) {
                Component component = container.getComponent(i);
                if (component instanceof JApplet) {
                    layeredPane = ((JApplet) component).getLayeredPane();
                } else if (component instanceof Container) {
                    return getLayeredPane((Container) component);
                }
            }
        }
        return layeredPane;
    }
}

Related Tutorials