List of usage examples for java.awt Component hasFocus
public boolean hasFocus()
From source file:Main.java
public static boolean hasOrContainsFocus(Component c) { if (c.hasFocus()) { return true; }/*w w w. j a v a2 s .c om*/ if (c instanceof Container) { Container container = (Container) c; for (Component childComponent : container.getComponents()) { if (hasOrContainsFocus(childComponent)) { return true; } } } return false; }
From source file:Main.java
public static Component getFirstChildComponent(Container container, Class ofType) { java.awt.Component[] comps = container.getComponents(); Component comp = null; for (int n = 0; n < comps.length; n++) { System.out.println("WHat component am I " + n + ":" + comps[n] + " IN " + container); if (ofType.isInstance(comps[n])) return comps[n]; if (comps[n] instanceof JComponent || comps[n] instanceof Container) comp = getFirstChildComponent((Container) comps[n], ofType); if (comp != null) { // Does this component have the focus? boolean hasFocus = comp.hasFocus(); if (hasFocus) return comp; }/* w w w. j a v a 2 s . c o m*/ } return null; }
From source file:MouseEnterFocusMover.java
public void mouseEntered(MouseEvent mouseEvent) { Component component = mouseEvent.getComponent(); if (!component.hasFocus()) { component.requestFocusInWindow(); }//from w w w.ja v a2 s. c o m }
From source file:self.philbrown.javaQuery.$.java
/** * Searches the view hierarchy rooted at the given view in order to find the currently * selected view//from w w w . j a v a 2 s . c o m * @param view the view to search within * @return the selected view, or null if no view in the given hierarchy was found. */ private Component recursivelyFindSelectedSubView(Component view) { if (view.hasFocus()) return view; else if (view instanceof Container) { Component v = null; for (int i = 0; i < ((Container) view).getComponentCount(); i++) { v = recursivelyFindSelectedSubView(((Container) view).getComponent(i)); if (v != null) return v; } return null; } else return null; }
From source file:self.philbrown.javaQuery.$.java
/** * Gives focus to the first focusable view in the current selection. * @return this/*from w w w. j av a 2s . co m*/ */ public $ focus() { for (Component view : this.views) { view.requestFocus(); if (view.hasFocus()) { break; } } return this; }