Example usage for java.awt Component isVisible

List of usage examples for java.awt Component isVisible

Introduction

In this page you can find the example usage for java.awt Component isVisible.

Prototype

@Transient
public boolean isVisible() 

Source Link

Document

Determines whether this component should be visible when its parent is visible.

Usage

From source file:Main.java

public static boolean isComponentVisible(Component comp) {
    if (!comp.isVisible() && !isRootComponent(comp)) {
        return false;
    }/*w  ww .  ja  v a2 s.  com*/
    Component parent = comp.getParent();

    return parent == null || isComponentVisible(parent);

}

From source file:Util.java

public static final Component getVisibleChildAt(Container container, Point p) {
    for (int i = 0; i < container.getComponentCount(); i++) {
        Component c = container.getComponent(i);
        if (c.isVisible() && c.contains(p.x - c.getX(), p.y - c.getY()))
            return c;
    }/*from w  w  w  . j a  va 2 s.co m*/

    return null;
}

From source file:Main.java

private static void invalidateSubtreeRec(Component c) {
    if (c != null && c.isVisible()) {
        c.invalidate();//w w w.ja  v a 2  s.  c  om
        if (c instanceof Container) {
            for (Component child : ((Container) c).getComponents()) {
                invalidateSubtreeRec(child);
            }
        }
    }
}

From source file:Main.java

public static boolean isOnlyVisibleComponent(Component c) {
    return c != null && c.isVisible() && getVisibleChildrenCount(c.getParent()) == 1;
}

From source file:Main.java

public static boolean isFocusable(Component c) {
    return c.isFocusable() && c.isDisplayable() && c.isVisible() && c.isEnabled();
}

From source file:Main.java

public static void centralizeComponent(Component component, Component otherComponent) {

    Dimension othersDimension = null;
    Point othersLocation = null;// www  . j a va 2 s .c o  m
    if (otherComponent == null || !otherComponent.isVisible()) {
        othersDimension = Toolkit.getDefaultToolkit().getScreenSize();
        othersLocation = new Point(0, 0);
    } else {
        othersDimension = otherComponent.getSize();
        othersLocation = otherComponent.getLocation();
    }
    Point centerPoint = new Point(
            (int) Math.round(othersDimension.width / HALF - component.getWidth() / HALF) + othersLocation.x,
            (int) Math.round(othersDimension.height / HALF - component.getHeight() / HALF) + othersLocation.y);
    component.setLocation(centerPoint);
}

From source file:Main.java

public static boolean isVisible(final Component component) {
    if (component != null) {
        if (SwingUtilities.isEventDispatchThread()) {
            return component.isVisible();
        } else {//from w w  w  . j a  v a  2s  .co  m
            final boolean[] isVisible = new boolean[1];

            try {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        isVisible[0] = component.isVisible();
                    }
                });
            } catch (InterruptedException | InvocationTargetException e) {

            }

            return isVisible[0];
        }
    } else {
        return false;
    }
}

From source file:net.chaosserver.timelord.swingui.SwingUtil.java

/**
 * Repair location is designed to detect if a box is partially
 * off-screen and move the box back onto the screen.
 *
 * @param component component to repair//from w  w  w  . j a  v  a  2 s .c  o m
 */
public static void repairLocation(Component component) {
    Point locationPoint = component.getLocation();
    Point locationOnScreenPoint = null;
    if (component.isVisible()) {
        locationOnScreenPoint = component.getLocationOnScreen();
    }
    Dimension componentSize = component.getSize();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    if (log.isDebugEnabled()) {
        log.debug("Repairing location on [" + component.getClass().getName() + "].  Original location point = ["
                + locationPoint + "] and location on screen point = [" + locationOnScreenPoint
                + "].  The screen size is [" + screenSize + "] and the component size is [" + componentSize
                + "]");
    }

    // Is the dialog to far to the left?  Then fix.
    if (locationPoint.getX() < 0) {
        locationPoint.setLocation(0, locationPoint.getY());
    }
    if (locationPoint.getY() < 0) {
        locationPoint.setLocation(locationPoint.getX(), 0);
    }
    // component.setLocation(locationPoint);

    // Is the dialog too wide?
    if (locationPoint.getX() + componentSize.getWidth() > screenSize.getWidth()) {

        componentSize.width = (int) (screenSize.getWidth() - locationPoint.getX());
    }
    if (locationPoint.getY() + componentSize.getHeight() > screenSize.getHeight()) {

        componentSize.height = (int) (screenSize.getHeight() - locationPoint.getY());
    }

    // component.setSize(componentSize);
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private static void paintComponents(Container c, Graphics g) {
    if (!c.isShowing())
        return;/*from w  w  w . j a v a2s  .com*/

    final int ncomponents = c.getComponentCount();
    final Rectangle clip = g.getClipBounds();

    int i = ncomponents - 1;
    while (i >= 0) {
        final Component component[] = c.getComponents();
        final Component comp = component[i];
        if (comp == null || !comp.isVisible())
            continue;
        final Rectangle bounds = comp.getBounds();
        Rectangle cr;
        if (clip == null)
            cr = new Rectangle(bounds);
        else
            cr = bounds.intersection(clip);
        if (cr.isEmpty())
            continue;

        final Graphics cg = g.create();
        cg.setClip(cr);
        cg.translate(bounds.x, bounds.y);
        try {
            comp.paint(cg);
        } catch (Throwable e) {
            //
        }

        cg.dispose();
        i--;
    }
}

From source file:Main.java

public static String formateComponentInfosToPrint(Component comp) {
    StringBuilder buf = new StringBuilder();
    buf.append(comp.getClass().getSimpleName());
    buf.append(" [");
    buf.append(comp.getName());/* ww  w .  j a v a 2 s .co  m*/
    if (comp instanceof JLabel)
        buf.append(",\"").append(((JLabel) comp).getText()).append("\"");
    buf.append(",");
    buf.append(comp.getClass().getName());
    buf.append(",");
    buf.append(comp.isVisible() ? "visible" : "not visible");
    buf.append(",");
    buf.append(comp.isValid() ? "valid" : "invalid");
    buf.append("]");
    return buf.toString();
}