| | |
| | | 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; |
| | |
| | | { |
| | | JTextField f = new JTextField(); |
| | | updateTextFieldComponent(f, text, tooltip, size, style); |
| | | f.addFocusListener(new TextFieldFocusListener(f)); |
| | | return f; |
| | | } |
| | | |
| | |
| | | { |
| | | JPasswordField f = new JPasswordField(); |
| | | updateTextFieldComponent(f, text, tooltip, size, style); |
| | | f.addFocusListener(new TextFieldFocusListener(f)); |
| | | return f; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 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) |
| | | { |
| | | } |
| | | } |