List of usage examples for java.awt Frame isFocused
public boolean isFocused()
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 . j ava 2s.co 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:org.freeplane.main.application.MapViewDockingWindows.java
public void focusMapViewLater(final MapView mapView) { Timer timer = new Timer(40, new ActionListener() { int retryCount = 5; public void actionPerformed(final ActionEvent event) { final Timer eventTimer = (Timer) event.getSource(); focusMapLater(mapView, eventTimer); }/*from w ww .java 2 s . c o m*/ private void focusMapLater(final MapView mapView, final Timer eventTimer) { if (mapView.isShowing() && Controller.getCurrentController().getMapViewManager().getMapViewComponent() == mapView) { final NodeView selected = mapView.getSelected(); if (selected != null) { final Frame frame = JOptionPane.getFrameForComponent(mapView); if (frame.isFocused()) selected.requestFocusInWindow(); else frame.addWindowFocusListener(new WindowAdapter() { @Override public void windowGainedFocus(WindowEvent e) { frame.removeWindowFocusListener(this); selected.requestFocusInWindow(); retryCount = 2; eventTimer.start(); } }); } } if (retryCount > 1) { retryCount--; eventTimer.start(); } } }); timer.setRepeats(false); timer.start(); }