Example usage for java.awt Frame isShowing

List of usage examples for java.awt Frame isShowing

Introduction

In this page you can find the example usage for java.awt Frame isShowing.

Prototype

public boolean isShowing() 

Source Link

Document

Checks if this Window is showing on screen.

Usage

From source file:Main.java

public static Frame tryFindSuitableFrameOwner() {
    Frame owner = null;//w w  w.jav a2 s. c om
    // find a suitable owner, if any
    Frame[] allFrames = Frame.getFrames();
    if (allFrames != null) {
        for (Frame frame : allFrames) {
            if (frame == null)
                continue;
            if (!frame.isShowing())
                continue;
            if (!frame.isActive())
                continue;
            owner = frame;
            break;
        }
    }
    return owner;
}

From source file:Main.java

/**
 * Utility method that finds the first focused frame. If no frame
 * is focused, then the first visible frame will be returned. 
 * If no frame is visible, then the first frame created by this
 * application will be returned. If no frame was created yet,
 * then <code>null</code> will be returned.
 *  //from w  w w .  ja va  2 s.c o m
 * @return The potential parent window for a dialog
 */
static Window findParentWindow() {
    Frame frames[] = JFrame.getFrames();
    if (frames.length == 0) {
        return null;
    }
    for (Frame f : frames) {
        if (f.isFocused()) {
            return f;
        }
    }
    for (Frame f : frames) {
        if (f.isShowing()) {
            return f;
        }
    }
    return frames[0];
}

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);/*from   www  . ja  v  a  2 s. co m*/
        }

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>/*w w w  .j  a  v  a2  s .  c  o  m*/
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}