Java Utililty Methods JComponent Container

List of utility methods to do JComponent Container

Description

The list of methods to do JComponent Container are organized into topic(s).

Method

ComponentgetRoot(Component comp)
Returns the "root" of the component tree containint comp The root is defined as either the least ancestor of comp which is a Window , or the greatest ancestor of comp which is a Applet if no Window ancestors are found.
Applet app = null;
Window win = null;
while (comp != null) {
    if (win == null && comp instanceof Window)
        win = (Window) comp;
    else if (comp instanceof Applet)
        app = (Applet) comp;
    comp = comp.getParent();
...
JDialoggetRoot(JComponent pchildComponent)
get Root
Container objParent = pchildComponent.getParent();
while (objParent != null) {
    objParent = objParent.getParent();
    if (objParent instanceof JDialog) {
        return (JDialog) objParent;
return null;
...
ContainergetRootContainer(Component c)
get Root Container
if (c == null) {
    return null;
Container parent = c.getParent();
while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame)
        && !(parent instanceof Window) && (parent.getParent() != null)) {
    parent = parent.getParent();
return parent;
ContainergetRootContainer(Component c)
get Root Container
if (c != null) {
    Container parent = c.getParent();
    while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame)
            && !(parent instanceof Window) && (parent.getParent() != null)) {
        parent = parent.getParent();
    return parent;
return null;
ContainergetRootContainer(Component c)
get Root Container
if (c == null) {
    return null;
Container parent = c.getParent();
while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame)
        && !(parent instanceof Window) && (parent.getParent() != null)) {
    parent = parent.getParent();
return parent;
ContainergetRootContainer(Component c)
get Root Container
if (c == null) {
    return null;
Container parent = c.getParent();
while ((parent != null) && !(parent instanceof JPopupMenu) && !(parent instanceof JInternalFrame)
        && !(parent instanceof Window) && (parent.getParent() != null)) {
    parent = parent.getParent();
return parent;
JRootPanegetRootPane(Component cmp)
Returns the root pane or null.
return SwingUtilities.getRootPane(cmp);
JRootPanegetRootPane(final Component component)
Returns root pane for the specified component or null if it doesn't exist.
if (component == null) {
    return null;
} else if (component instanceof JFrame) {
    return ((JFrame) component).getRootPane();
} else if (component instanceof JDialog) {
    return ((JDialog) component).getRootPane();
} else if (component instanceof JWindow) {
    return ((JWindow) component).getRootPane();
...
RootPaneContainergetRootPaneContainer(Component c)
get Root Pane Container
if (c instanceof RootPaneContainer) {
    return (RootPaneContainer) c;
for (Container p = c.getParent(); p != null; p = p.getParent()) {
    if (p instanceof RootPaneContainer) {
        return (RootPaneContainer) p;
return null;
RootPaneContainergetRootPaneContainer(Component c)
Gets the root pane container of a component.
for (; c != null; c = c.getParent()) {
    if (c instanceof RootPaneContainer) {
        return (RootPaneContainer) c;
return null;