src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
Print this page
*** 29,38 ****
--- 29,39 ----
import java.awt.Dimension;
import java.awt.Point;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+ import java.awt.event.FocusEvent;
import java.awt.peer.TextFieldPeer;
import javax.swing.JPasswordField;
import javax.swing.text.JTextComponent;
*** 95,104 ****
--- 96,120 ----
public void actionPerformed(final ActionEvent e) {
postEvent(new ActionEvent(getTarget(), ActionEvent.ACTION_PERFORMED,
getText(), e.getWhen(), e.getModifiers()));
}
+ /**
+ * Restoring native behavior. We should sets the selection range to zero,
+ * when component lost its focus.
+ *
+ * @param e the focus event
+ */
+ @Override
+ protected void handleJavaFocusEvent(final FocusEvent e) {
+ if (e.getID() == FocusEvent.FOCUS_LOST) {
+ // In order to de-select the selection
+ setCaretPosition(0);
+ }
+ super.handleJavaFocusEvent(e);
+ }
+
private final class JTextAreaDelegate extends JPasswordField {
// Empty non private constructor was added because access to this
// class shouldn't be emulated by a synthetic accessor method.
JTextAreaDelegate() {