Mega Code Archive

 
Categories / Java / Swing JFC
 

Gets the content pane of the given window

//package com.javadocking.util; import java.awt.Container; import java.awt.Window; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JWindow; /**  * This class contains a collection of static utility methods for Swing.  *   * @author Heidi Rakels.  */ public class SwingUtil {   /**    * Gets the content pane of the given window.    *     * @param   window      The window. It should inherit from javax.swing.JFrame,    *               javax.swing.JDialog or javax.swing.JWindow.    * @return           The content pane of the window.     *               If the given window is not a javax.swing.JFrame,    *               javax.swing.JDialog or javax.swing.JWindow, null is returned.    */   public static Container getContentPane(Window window)   {     // Get the layered pane if we can find one.     if (window instanceof JFrame)        return ((JFrame)window).getContentPane();     if (window instanceof JDialog)        return ((JDialog)window).getContentPane();     if (window instanceof JWindow)        return ((JWindow)window).getContentPane();     // We could not find a root pane for this window.     return null;          } }