Class SelectOnFocusGained

  extended by java.awt.event.FocusAdapter
      extended by be.ugent.caagt.swirl.SelectOnFocusGained
All Implemented Interfaces:
java.awt.event.FocusListener, java.util.EventListener

public class SelectOnFocusGained
extends java.awt.event.FocusAdapter

Focus listener which automatically selects the contents of a text component when it gains focus. This is a singleton class without a public constructor. The shared singleton instance of this class should be used through the class method register(javax.swing.text.JTextComponent).

As an example, the following code creates a text field textField and ensures that the contents of the field will be selected automatically whenever we enter the field (e.g., by tabbing to it or by moving the focus to it programmatically).

    JTextField textField = new JTextField (10);
    SelectOnFocusGained.register (textField);

Method Summary
 void focusGained(java.awt.event.FocusEvent e)
static void register(javax.swing.text.JTextComponent component)
          Registers a shared focus listener of this type with the given component.
static void unregister(javax.swing.text.JTextComponent component)
          Unregisters the shared focus listener with the given component.
Methods inherited from class java.awt.event.FocusAdapter
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static void register(javax.swing.text.JTextComponent component)
Registers a shared focus listener of this type with the given component. The effect is that the the contents of the component will be selected automatically whenever the field gains the focus.


public static void unregister(javax.swing.text.JTextComponent component)
Unregisters the shared focus listener with the given component.


public void focusGained(java.awt.event.FocusEvent e)
Specified by:
focusGained in interface java.awt.event.FocusListener
focusGained in class java.awt.event.FocusAdapter