Java Code Examples for javax.swing.JFrame.isVisible()

The following are Jave code examples for showing how to use isVisible() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: SwingBrowserTest.java   View Source Code Vote up 6 votes
private void waitForLoading(final URL url, final JFrame f, final HtmlBrowser.Impl impl) 
        throws InvocationTargetException, InterruptedException {

    for (int i = 0; i < 10 && f.isVisible(); i++) {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                URL current = impl.getURL();
                if (url.equals(current)) {
                    f.setVisible(false);
                    f.dispose();
                }
            }
        });
        Thread.sleep(i*100);
    }
}
 
Example 2
Project: PhySIX   File: Display.java   View Source Code Vote up 5 votes
/**
 * creates a JFrame and a background Thread managing the rendering and the Frame itself.
 */
public static void create(){
if(!running){
	running = true;
	GFrame = new JFrame();
	GFrame.setVisible(true);
	RefreshWindow();
	RegisterInputDevices();
	BStrategy = GFrame.getBufferStrategy();
	setCurrentscreen(new EmptyScreen());
	PhySIX = new Thread(new Runnable(){
		@Override
		public void run() {
			try {
				while(GFrame.isVisible()){
					Graphics g = BStrategy.getDrawGraphics();
					clearScreen(g);
					updateDHs(g);
					renderDHs(g);
					drawDHs(g);
					drawmodels(g);
					UpdateStrat(g);
					Sync();
				}
			} catch (LessThanZeroException e) {
				e.printStackTrace();
			}
		}
	}, "Display-Loop-Thread.");
	PhySIX.start();
}
}
 
Example 3
Project: pm-home-station   File: Station.java   View Source Code Vote up 5 votes
private void saveScreenAndDimensions(JFrame frame) {
    if (!frame.isVisible()) {
        return;
    }

    // check multiple displays
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screens = ge.getScreenDevices();
    Point pos = frame.getLocationOnScreen();
    Dimension size = frame.getSize();
    if (screens.length == 1) {
        Config.instance().to().setProperty(Config.Entry.POS_X.key(), pos.x);
        Config.instance().to().setProperty(Config.Entry.POS_Y.key(), pos.y);
        Config.instance().to().setProperty(Config.Entry.POS_WIDTH.key(), size.width);
        Config.instance().to().setProperty(Config.Entry.POS_HEIGHT.key(), size.height);
        logger.info("Saved window dimensions to config file (single screen found)");
    } else {
        Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
        pos.x -= screenBounds.x;
        pos.y -= screenBounds.y;
        GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_X.key(), pos.x);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_Y.key(), pos.y);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_WIDTH.key(), size.width);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_HEIGHT.key(), size.height);
        
        Config.instance().to().setProperty(Config.Entry.SCREEN.key(), device.getIDstring());
        logger.info("Saved window dimensions to config file (multi screen found)");
    }
    
}
 
Example 4
Project: jmt   File: PartialTitleFrameMatcher.java   View Source Code Vote up 4 votes
@Override
public boolean isMatching(JFrame frame) {
	return frame.isVisible() && frame.getTitle().startsWith(textToMatch);
}
 
Example 5
Project: openjdk-jdk10   File: MouseClickRequestFocusRaceTest.java   View Source Code Vote up 4 votes
public static void test() {
    // Right click Frame-1
    robot.mouseMove(frame1.getLocation().x + 100, frame1.getLocation().y + 200);
    robot.mousePress(InputEvent.BUTTON3_MASK);
    robot.mouseRelease(InputEvent.BUTTON3_MASK);

    robot.delay(1000);

    // Left click Frame-2
    robot.mouseMove(frame2.getLocation().x + 100, frame1.getLocation().y + 200);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    robot.delay(1000);

    JComponent focusOwner = (JComponent)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    JFrame focusedWindow = (JFrame)KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();

    System.out.println("focus owner: " + focusOwner);
    System.out.println("focused window: " + focusedWindow);

    // Verify that the focused window is the ancestor of the focus owner
    if (!focusedWindow.isAncestorOf(focusOwner)) {
        throw new RuntimeException("The focus owner is not in the focused window!");
    }

    if (!OSInfo.getOSType().equals(OSInfo.OSType.MACOSX)) {
        // Try to close native focused window
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_F4);
        robot.keyRelease(KeyEvent.VK_F4);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.delay(1000);
        // Verify that the Java focused window really mapped the native focused window.
        if (focusedWindow.isVisible()) {
            throw new RuntimeException("The focused window is different on Java and on the native level.");
        }
    } else {
        // Try to move native focus to previous window
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_F4);
        robot.keyRelease(KeyEvent.VK_F4);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.delay(1000);
        // Verify that the Java focused window really mapped the native focused window.
        if (focusedWindow.isFocused()) {
            throw new RuntimeException("The focused window is different on Java and on the native level.");
        }
    }
}