mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
05.56.2007 91c4164abf42bbfceb2c31948f3af09ef022843f
Fix for issue 1634 (select text field content upon tab into).

The fix consists of selecting the whole text of the textfield when we get the keyboard focus (so it applies both to the tab key and the mouse click on the text field).
1 files modified
45 ■■■■■ changed files
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java 45 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/UIFactory.java
@@ -34,6 +34,8 @@
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
@@ -834,6 +836,7 @@
  {
    JTextField f = new JTextField();
    updateTextFieldComponent(f, text, tooltip, size, style);
    f.addFocusListener(new TextFieldFocusListener(f));
    return f;
  }
@@ -852,6 +855,7 @@
  {
    JPasswordField f = new JPasswordField();
    updateTextFieldComponent(f, text, tooltip, size, style);
    f.addFocusListener(new TextFieldFocusListener(f));
    return f;
  }
@@ -1775,3 +1779,44 @@
    }
  }
}
/**
 * A class used to be able to select the contents of the text field when
 * it gets the focus.
 *
 */
class TextFieldFocusListener implements FocusListener
{
  private JTextField tf;
  /**
   * The constructor for this listener.
   * @param tf the text field associated with this listener.
   */
  TextFieldFocusListener(JTextField tf)
  {
    this.tf = tf;
  }
  /**
   * {@inheritDoc}
   */
  public void focusGained(FocusEvent e)
  {
    if ((tf.getText() == null) || "".equals(tf.getText()))
    {
      tf.setText(" ");
      tf.selectAll();
      tf.setText("");
    }
    else
    {
      tf.selectAll();
    }
  }
  /**
   * {@inheritDoc}
   */
  public void focusLost(FocusEvent e)
  {
  }
}