public static void requestFocus(Project project, final boolean useRobot) { JFrame frame = WindowManager.getInstance().getFrame(project); // the only reliable way I found to bring it to the top boolean aot = frame.isAlwaysOnTop(); frame.setAlwaysOnTop(true); frame.setAlwaysOnTop(aot); int frameState = frame.getExtendedState(); if ((frameState & Frame.ICONIFIED) == Frame.ICONIFIED) { // restore the frame if it is minimized frame.setExtendedState(frameState ^ Frame.ICONIFIED); } frame.toFront(); frame.requestFocus(); if (useRobot && runningOnWindows7()) { try { // remember the last location of mouse final Point oldMouseLocation = MouseInfo.getPointerInfo().getLocation(); // simulate a mouse click on title bar of window Robot robot = new Robot(); robot.mouseMove(frame.getX(), frame.getY()); robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); // move mouse to old location robot.mouseMove((int) oldMouseLocation.getX(), (int) oldMouseLocation.getY()); } catch (Exception ex) { // just ignore exception, or you can handle it as you want } finally { frame.setAlwaysOnTop(false); } } }
public void openCaptureWindow() { if (framenr - lastcapture_framenr < number_of_frames_before_cwopen) { return; } // Capture Window cw.setVisible(true); cw.toFront(); // Timer for closing the capturewindow TimerTask task = new TimerTask() { @Override public void run() { EventQueue.invokeLater( new Runnable() { public void run() { System.out.println("Closing cw..."); cw.setVisible(false); cwText.setText(""); // Empty text in case there is a text } }); } }; cwTimer = new Timer(); cwTimer.schedule(task, number_of_second_capturewindow * 1000); }
public void bringWindowToFront(int index) { if (index >= 0 && index < controllers.size()) { SwingController controller = controllers.get(index); JFrame frame = controller.getViewerFrame(); if (frame != null) { frame.setState(Frame.NORMAL); frame.toFront(); } } }
public void bringAllWindowsToFront(SwingController frontMost) { JFrame frontMostFrame = null; for (int i = 0; i < controllers.size(); i++) { SwingController controller = controllers.get(i); JFrame frame = controller.getViewerFrame(); if (frame != null) { if (frontMost == controller) { frontMostFrame = frame; continue; } frame.setState(Frame.NORMAL); frame.toFront(); } } if (frontMostFrame != null) { frontMostFrame.setState(Frame.NORMAL); frontMostFrame.toFront(); } }
public static void toFullScreen( JFrame window, GraphicsDevice gd, boolean tryAppleFullscreen, boolean tryExclusiveFullscreen) { if (appleEawtAvailable() && tryAppleFullscreen && appleOSVersion() >= 7 && // lion and above javaVersion() >= 7) { // java 7 and above System.out.println("trying to apple fullscreen"); enableAppleFullscreen(window); doAppleFullscreen(window); } else if (appleEawtAvailable() && // Snow Leopard and below OR apple java 6 and below TODO: test this on SL tryExclusiveFullscreen && gd.isFullScreenSupported()) { if (javaVersion() >= 7) setAutoRequestFocus(window, true); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); // window.setExtendedState(JFrame.MAXIMIZED_BOTH); gd.setFullScreenWindow(window); window.toFront(); Rectangle r = gd.getDefaultConfiguration().getBounds(); window.setBounds(r); // window.pack(); } else { // Windows and Linux TODO: test this window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setUndecorated(true); window.setSize(gd.getDisplayMode().getWidth(), gd.getDisplayMode().getHeight()); window.setLocation(0, 0); window.setExtendedState(JFrame.MAXIMIZED_BOTH); window.toFront(); } window.pack(); window.setVisible(true); }
public void bringToFront() { jFrame.toFront(); }