com.isti.util.gui
Class FocusUtils

java.lang.Object
  extended by com.isti.util.gui.FocusUtils

public class FocusUtils
extends java.lang.Object

Class FocusUtils defines a set of static utility methods related to component focus.


Method Summary
static void disableFocusComponents(java.awt.Container contObj, java.awt.Component keepFocusObj)
          Disables focusability on all components held by the given container or any subcontainers of it, except for any component matching the 'keepFocusObj' component or that is any type of menu item.
static java.awt.Component findFirstFocusableComponent(java.awt.Container contObj, java.lang.Class preferredType)
          Finds the first component of the preferred class-type among all the components held by the given container or any subcontainers of it.
static java.awt.Component findFocusedComponent(java.awt.Container contObj)
          Finds the first focused component held by the given container or any subcontainers of it
static boolean requestDefaultFocus(javax.swing.JComponent jCompObj)
          Non-deprecated version of JComponent 'requestDefaultFocus()' method.
static void restoreTabFocusTraversal(java.awt.Container containerObj)
          Restores the focus-traversal function of the "Tab" key.
static void setComponentFocusDisabled(java.awt.Component compObj)
          Disables focusability on the given component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setComponentFocusDisabled

public static void setComponentFocusDisabled(java.awt.Component compObj)
Disables focusability on the given component. If running under Java 1.4 or later then "setFocusable(false)" is used.

Parameters:
compObj - the component to use.

disableFocusComponents

public static void disableFocusComponents(java.awt.Container contObj,
                                          java.awt.Component keepFocusObj)
Disables focusability on all components held by the given container or any subcontainers of it, except for any component matching the 'keepFocusObj' component or that is any type of menu item.

Parameters:
contObj - the container to use.
keepFocusObj - the component that should retain focusability, or null for none.

findFirstFocusableComponent

public static java.awt.Component findFirstFocusableComponent(java.awt.Container contObj,
                                                             java.lang.Class preferredType)
Finds the first component of the preferred class-type among all the components held by the given container or any subcontainers of it. If a matching component is not found then the first focusable component is returned, or null if none could be found.

Parameters:
contObj - the container to use.
preferredType - the preferred class-type to be found.
Returns:
A focusable component, or null if none could be found.

findFocusedComponent

public static java.awt.Component findFocusedComponent(java.awt.Container contObj)
Finds the first focused component held by the given container or any subcontainers of it

Parameters:
contObj - the container to use.
Returns:
A focused 'Component', or null if none found.

restoreTabFocusTraversal

public static void restoreTabFocusTraversal(java.awt.Container containerObj)
Restores the focus-traversal function of the "Tab" key. (Some text components like 'JTextArea' redefine the "Tab" key.) This method only works for Java 1.4 or later. Under Java 1.3, the focus-traversal function of the "Tab" key may be restored by extending the component to make the 'isManagingFocus()' method return 'false'.

Parameters:
containerObj - the component to use.

requestDefaultFocus

public static boolean requestDefaultFocus(javax.swing.JComponent jCompObj)
Non-deprecated version of JComponent 'requestDefaultFocus()' method. Requests focus on the given JComponent's FocusTraversalPolicy's default Component. If the JComponent is a focus cycle root, then its FocusTraversalPolicy is used. Otherwise, the FocusTraversalPolicy of the JComponent's focus-cycle-root ancestor is used.

Parameters:
jCompObj - JComponent object to use.
Returns:
true if a focus cycle root was found and used.