Here you can find the source of getWindowSize(JComponent start)
Parameter | Description |
---|---|
start | enclosed component |
public static Dimension getWindowSize(JComponent start)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.*; public class Main { /**/*w w w.j a v a 2 s .c o m*/ * return the size of the window * * @param start enclosed component * @return */ public static Dimension getWindowSize(JComponent start) { return getTopAncestor(start).getSize(); } public static Component getTopAncestor(Component c) { Component ret = c.getParent(); if (ret == null) return c; return getTopAncestor(ret); } /** * search of the hierarcy of components for an instance of a given class * * @param start - starting component * @param theClass - required class * @return possibly null component - null says no ancestor found */ public static Container getTopAncestor(JComponent start) { Container parent = start.getParent(); if (parent == null) return start; if (parent instanceof JComponent) return getTopAncestor((JComponent) parent); if (parent instanceof JFrame) return parent; if (parent instanceof JDialog) return parent; if (parent instanceof JWindow) return parent; else return null; } }