List of utility methods to do Swing Focus
boolean | isFocused(Component component, boolean recoursive) is Focused if (component.isFocusOwner()) return true; if (recoursive && component instanceof JComponent) { JComponent parentComponent = (JComponent) component; for (Component childComponent : parentComponent.getComponents()) { if (isFocused(childComponent, recoursive)) { return true; return false; |
boolean | isParentWindowFocused(Component component) is Parent Window Focused Window window = SwingUtilities.getWindowAncestor(component);
return window != null && window.isFocused();
|
boolean | isParentWindowFocused(Component component) true if the given Component 's parent Window is currently active (focused). Window window = SwingUtilities.getWindowAncestor(component);
return window != null && window.isFocused();
|
boolean | isParentWindowFocused(Component component) true if the given Component 's has a parent Window (i.e. final Window window = SwingUtilities.getWindowAncestor(component); return window != null && window.isFocused(); |
void | paintFocusRect(Graphics g, Rectangle r) paint Focus Rect BasicGraphicsUtils.drawDashedRect(g, r.x - 1, r.y, r.width + 2, r.height); |
void | postponeFocus(final Component target) Setta il focus su form modali SwingUtilities.invokeLater(new Runnable() { public void run() { target.dispatchEvent(new FocusEvent(target, FocusEvent.FOCUS_GAINED)); }); |
void | removeFocus(JComponent component) Makes sure the component won't receive the focus. component.setRequestFocusEnabled(false); component.setFocusable(false); |
void | requestComponentFocus(final Window win, final JComponent comp) Registers a (temporary) WindowListener with the window that will activate the passed component as soon as the windowActivated() event is received. win.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent evt) { EventQueue.invokeLater(new Runnable() { @Override public void run() { comp.requestFocus(); }); win.removeWindowListener(this); }); |
void | requestComponentFocus(final Window win, final JComponent comp) Registers a (temporary) WindowListener with the window that will activate the passed component as soon as the windowActivated() event is received. win.addWindowListener(new WindowAdapter() { @Override public void windowActivated(WindowEvent evt) { EventQueue.invokeLater(comp::requestFocus); win.removeWindowListener(this); }); |
void | requestFocus(final JComponent comp) Schedules a requestFocus() call in the AWT event queue. if (comp == null) return; EventQueue.invokeLater(new Runnable() { @Override public void run() { comp.requestFocus(); }); ... |