Example usage for javax.swing JComponent getTopLevelAncestor

List of usage examples for javax.swing JComponent getTopLevelAncestor

Introduction

In this page you can find the example usage for javax.swing JComponent getTopLevelAncestor.

Prototype

@BeanProperty(bound = false)
@SuppressWarnings("deprecation")
public Container getTopLevelAncestor() 

Source Link

Document

Returns the top-level ancestor of this component (either the containing Window or Applet), or null if this component has not been added to any container.

Usage

From source file:Main.java

public static boolean isFrameActive(JComponent c) {
    return c != null && (!(c.getTopLevelAncestor() instanceof Window)
            || isWindowActive((Window) c.getTopLevelAncestor()));

}

From source file:Main.java

public static boolean isFrameActive(JComponent c) {
    if (c == null) {
        return false;
    }//from ww  w  .j av  a2s . co m

    if (c.getTopLevelAncestor() instanceof Window) {
        return isWindowActive((Window) c.getTopLevelAncestor());
    }

    return true;
}

From source file:Main.java

public static void swapComponentsAndResizeUI(JComponent ui, JComponent current, JComponent next) {
    ui.remove(current);/*from www  .  j  a  va 2s  . c o m*/
    ui.add(next);
    current = next;
    Component c = ui.getTopLevelAncestor();
    if (c instanceof Window) {
        Window w = (Window) c;
        w.pack();
    }
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Returns a <code>MouseListener</code> that changes the cursor and
 * notifies <code>actionListener</code> on click.
 *//*ww  w. j  a v  a 2s  . c o  m*/
public static MouseListener getURLInputListener(final ActionListener actionListener) {
    return new MouseAdapter() {
        public void mouseEntered(MouseEvent e) {
            JComponent comp = (JComponent) e.getComponent();
            comp.getTopLevelAncestor().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            JComponent comp = (JComponent) e.getComponent();
            comp.getTopLevelAncestor().setCursor(Cursor.getDefaultCursor());
        }

        public void mouseClicked(MouseEvent e) {
            actionListener.actionPerformed(new ActionEvent(e.getComponent(), 0, null));
        }
    };
}