List of utility methods to do Swing Focus
Component | focusComponentOrChild(Component c) Puts the focus on the first component in the tree of c that can accept the focus.
return focusComponentOrChild(c, false);
|
Component | focusComponentOrChild(Component c, boolean deepest) Puts the focus on the first component in the tree of c that can accept the focus.
final Component focusable = getFocusableComponentOrChild(c, deepest); if (focusable != null) { focusable.requestFocus(); return focusable; |
boolean | focusFirstFocusableChild(Container c) focus First Focusable Child int len = c.getComponentCount(); for (int i = 0; i < len; i++) { if (focusFirstFocusableComponent(c)) { return true; return false; |
boolean | focusFirstFocusableComponent(Component c) focus First Focusable Component if (c == null) { return false; if (c instanceof JComponent) { if (((JComponent) c).isRequestFocusEnabled() && c.requestFocusInWindow()) { return true; if (c.isFocusable() && c.requestFocusInWindow()) { return true; if (!(c instanceof Container)) { return false; return focusFirstFocusableChild((Container) c); |
void | focusLater(final Component component) focus Later SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (component instanceof JTextComponent) { ((JTextComponent) component).selectAll(); component.requestFocusInWindow(); }); |
void | focusLater(final Component component) Focus a component. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (component instanceof JTextComponent) { ((JTextComponent) component).selectAll(); component.requestFocusInWindow(); }); |
void | focusOnOpen(final JComponent component) focus On Open component.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { component.requestFocusInWindow(); component.removeAncestorListener(this); public void ancestorRemoved(AncestorEvent event) { public void ancestorMoved(AncestorEvent event) { ... |
Component | getFocusableComponentOrChild(Component c, boolean deepest) Returns the first component in the tree of c that can accept the focus.
if (c != null && c.isEnabled() && c.isVisible()) { if (c instanceof Container) { Container cont = (Container) c; if (deepest == false) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; if (jc.isRequestFocusEnabled()) { return jc; ... |
Component | getFocusableComponentOrChild(Component c, boolean deepest) Returns the first component in the tree of c that can accept the focus.
if (c != null && c.isEnabled() && c.isVisible()) { if (c instanceof Container) { Container cont = (Container) c; if (!deepest) { if (c instanceof JComponent) { JComponent jc = (JComponent) c; if (jc.isRequestFocusEnabled()) { return jc; ... |
Component | getPermanentFocusOwner() get Permanent Focus Owner return FocusManager.getCurrentManager().getPermanentFocusOwner();
|