List of usage examples for java.awt Component isFocusable
public boolean isFocusable()
From source file:Main.java
public static boolean isFocusable(Component c) { return c.isFocusable() && c.isDisplayable() && c.isVisible() && c.isEnabled(); }
From source file:Main.java
/** * Returns whether atleast one of child components within the specified * container is focusable or not./*from www. j av a2 s.c o m*/ * * @param container * container to process * @return true if atleast one of child components within the specified * container is focusable, false otherwise */ public static boolean hasFocusableComponent(final Container container) { for (final Component component : container.getComponents()) { if (component.isFocusable()) { return true; } else if (component instanceof Container) { if (hasFocusableComponent((Container) component)) { return true; } } } return false; }
From source file:Main.java
/** * Returns first focusable component found in the container. * * @param container container to process * @return first focusable component found in the container *//*from w w w.j a v a2 s. com*/ public static Component findFocusableComponent(final Container container) { final FocusTraversalPolicy focusTraversalPolicy = container.getFocusTraversalPolicy(); if (focusTraversalPolicy != null) { return focusTraversalPolicy.getFirstComponent(container); } else { for (final Component component : container.getComponents()) { if (component.isFocusable()) { return component; } if (component instanceof Container) { final Component focusable = findFocusableComponent((Container) component); if (focusable != null) { return focusable; } } } return null; } }
From source file:Main.java
public static boolean focusFirstFocusableComponent(Component c) { if (c == null) { return false; }/* w w w . ja v a 2s . c o m*/ 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); }
From source file:Main.java
public static Component compositeRequestFocus(Component component) { if (component instanceof Container) { Container container = (Container) component; if (container.isFocusCycleRoot()) { FocusTraversalPolicy policy = container.getFocusTraversalPolicy(); Component comp = policy.getDefaultComponent(container); if (comp != null) { comp.requestFocus();//from www . j ava 2 s . co m return comp; } } Container rootAncestor = container.getFocusCycleRootAncestor(); if (rootAncestor != null) { FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy(); Component comp = policy.getComponentAfter(rootAncestor, container); if (comp != null && SwingUtilities.isDescendingFrom(comp, container)) { comp.requestFocus(); return comp; } } } if (component.isFocusable()) { component.requestFocus(); return component; } return null; }
From source file:edu.ku.brc.af.ui.forms.FormViewObj.java
/** * This will choose the first focusable UI component that doesn't have a value. * BUT! It always chooses a JTextField over anything else. * (NOTE: We may want a non-JTextField that is required to override a JTextField that is not.) * //from ww w .j a va 2 s .co m * @return the focusable first object. */ public Component getFirstFocusable() { int insertPos = Integer.MAX_VALUE; Component focusable = null; Component first = null; for (FVOFieldInfo compFI : compsList) { Component comp = compFI.getComp(); if (comp.isEnabled() && comp.isFocusable() && comp instanceof GetSetValueIFace) { Object val = ((GetSetValueIFace) comp).getValue(); if (val == null || (val instanceof String && StringUtils.isEmpty((String) val))) { if (comp instanceof ValFormattedTextFieldSingle) { ValFormattedTextFieldSingle vtf = (ValFormattedTextFieldSingle) comp; if (vtf.getFormatter() != null && vtf.getFormatter().isIncrementer()) { continue; } } boolean override = false;//focusable instanceof JTextField && !(comp instanceof JTextField); if (compFI.getInsertPos() < insertPos || override) { if (comp instanceof UIValidatable) { focusable = ((UIValidatable) comp).getValidatableUIComp(); } else { focusable = comp; } if (!override) // keep the same (lower) position as the original { insertPos = compFI.getInsertPos(); } } } if (compFI.getInsertPos() == 0) { first = comp; } } } if (focusable instanceof JTextField && !(first instanceof JTextField)) { return focusable; } return first != null ? first : focusable; }
From source file:org.jdal.swing.form.FormFocusTransversalPolicy.java
@Override public Component getComponentAfter(Container container, Component component) { // Fix awt bug looking for ComboBoxEditor instead ComboBox // see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205817 if (component.getParent() instanceof JComboBox) component = component.getParent(); int index = components.indexOf(component); if (index == -1) { // not owner Container childContainer = getTopmostProvider(container, component); if (childContainer == null) return getFirstComponent(container); FocusTraversalPolicy ftp = childContainer.getFocusTraversalPolicy(); if (ftp != null && ftp != this) { Component next = ftp.getComponentAfter(childContainer, component); if (next != ftp.getFirstComponent(container)) return next; // child cycle do {/*from w ww . j av a 2 s .c om*/ index = components.indexOf(childContainer); childContainer = childContainer.getParent(); } while (index == -1 || childContainer == null); if (index == -1) { log.warn("I can't figure what is the next component"); return getFirstComponent(container); } } } index++; if (index < components.size() && index >= 0) { Component c = getComponent(index); if (c.isEnabled() && c.isFocusable()) return c; else return getComponentAfter(container, c); } return getFirstComponent(container); }