be.ugent.caagt.swirl

Class SelectOnFocusGained


public class SelectOnFocusGained
extends 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(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

static void
register(JTextComponent component)
Registers a shared focus listener of this type with the given component.
static void
unregister(JTextComponent component)
Unregisters the shared focus listener with the given component.
@Override
void focusGained(FocusEvent e)

Method Details

register

public static void register(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.

unregister

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

void focusGained

public @Override void focusGained(FocusEvent e)