Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.awt.Window;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLayeredPane;
import javax.swing.JRootPane;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;

public class Main {
    /**
     * Gets the layered pane of the window of the given component.
     * The window of the root pane should be a javax.swing.JFrame, javax.swing.JDialog
     * or javax.swing.JWindow. Otherwise the layered pane of the rootpane is returned.
     * 
     * @param    rootPane      The root pane whose layered pane is retrieved.
     * @return                The layered pane.
     */
    public static JLayeredPane getLayeredPane(JRootPane rootPane) {

        // Get the window of the component.
        Window window = SwingUtilities.getWindowAncestor(rootPane);
        if (window != null) {
            // Get the layered pane if we can find one.
            if (window instanceof JFrame)
                return ((JFrame) window).getLayeredPane();
            if (window instanceof JDialog)
                return ((JDialog) window).getLayeredPane();
            if (window instanceof JWindow)
                return ((JWindow) window).getLayeredPane();
        }

        // Get the layered pane of the root pane immediately.
        return rootPane.getLayeredPane();

    }
}