Class SJPasswordField

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<com.vaadin.flow.component.textfield.PasswordField, String>
com.vaadin.flow.component.AbstractSinglePropertyField<com.vaadin.flow.component.textfield.PasswordField, String>
com.vaadin.flow.component.textfield.TextFieldBase<com.vaadin.flow.component.textfield.PasswordField, String>
com.vaadin.flow.component.textfield.PasswordField
com.vaadin.swingbridge.surrogates.SJPasswordField
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.textfield.PasswordField>, com.vaadin.flow.component.CompositionNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.textfield.PasswordField>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.textfield.PasswordField>, com.vaadin.flow.component.HasAriaDescription, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasPlaceholder, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.textfield.PasswordField, String>, String>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.textfield.PasswordField, String>, String>, com.vaadin.flow.component.InputNotifier, com.vaadin.flow.component.KeyNotifier, com.vaadin.flow.component.shared.HasAllowedCharPattern, com.vaadin.flow.component.shared.HasClearButton, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.textfield.TextFieldVariant>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<com.vaadin.flow.component.textfield.PasswordField, String>, String>, com.vaadin.flow.component.textfield.HasAutocapitalize, com.vaadin.flow.component.textfield.HasAutocomplete, com.vaadin.flow.component.textfield.HasAutocorrect, com.vaadin.flow.data.binder.HasValidator<String>, com.vaadin.flow.data.value.HasValueChangeMode, ComponentMixin, ContainerMixin, EnterClaims.Claimant, JComponentMixin, JTextComponentMixin, Serializable

public class SJPasswordField extends com.vaadin.flow.component.textfield.PasswordField implements JTextComponentMixin, EnterClaims.Claimant
Surrogate for JPasswordField, a consumer of SD_sjtextfield's JTextComponentMixin. Extends Vaadin PasswordField directly (is-a). Reaches the migrator either through :emulators.JPasswordField as peer, or as a richer-than- stock Vaadin component in its own right.

Why PasswordField as peer (not TextField)

Vaadin PasswordField renders <input type="password">, giving a native browser-side mask glyph plus optional reveal button — the exact functionality JPasswordField exists to provide. PasswordField extends TextFieldBase (not TextField), so SJPasswordField cannot inherit from SJTextField — instead the JTextField-shaped surface (columns / ActionListener-on-Enter / setAction / horizontalAlignment) is duplicated here. JDK JPasswordField extends JTextField so this surface is part of JPasswordField's contract; the duplication is the price of Vaadin's parallel-not-shared peer hierarchy. Could be lifted into a JTextFieldMixin later if a third consumer arrives — for now two consumers don't justify the lift.

Override surface against JTextComponentMixin

  • validate() — visibility-widening override required by ComponentMixin's public validate() contract. Vaadin PasswordField declares inherited validate() as protected (input validation, not Swing's layout cycle). Same shape SJTextField and SJToggleButton take per SD_sjtextfield / SD_toggle_checkbox_first_cut.

getText() is not overridden and returns cleartext, matching the JDK. See SD_sjpasswordfield's correction note: echoChar is a rendering concern only.

JPasswordField-specific surface

  • echoChar — default '*'. State round-trip only: no getter here reads it, exactly as in the JDK, where only BasicPasswordFieldUI's view consults it. setEchoChar(char) fires nothing — the JDK's setter is not bound. The rendered mask is governed by <input type="password"> client-side (Vaadin exposes no server-side toggle), so the visual stays masked regardless. Toggling the masked-vs-cleartext boundary (i.e. echoChar=0) WARNs per R_match_swing_errors sub-bucket (c) — see setEchoChar(char) for the full rationale and the PasswordField.setRevealButtonVisible(boolean) alternative.
  • getPassword() — returns a fresh char[] snapshot of the Document's contents. Caller is expected to zero the array after use so the cleartext password doesn't linger in the heap as a String.
  • copy / cut — inherited from the mixin's SHelper.onUnimplemented(Object, String, Object...) default. JDK beeps and refuses to keep cleartext out of the system clipboard; our WARN and-drop is the closest equivalent and keeps clipboard-safe semantics under R_match_swing_errors.
  • getUIClassID() == "PasswordFieldUI".

JTextField-shape surface (duplicated from SJTextField)

  • columns — setColumns(int) writes peer.setWidth of a CssConvert.columnsToCssWidth(int) character-column hint per R_layouts_close_enough close-enough; negative throws IAE per R_match_swing_errors.
  • horizontalAlignment — drop-and-WARN per SD_sjtextfield (Vaadin shadow DOM doesn't honor host text-align). R_match_swing_errors IAE on bad axis preserved.
  • ActionListener wiring on Enter — Vaadin addKeyPressListener(Key.ENTER, ...) fires ActionEvent with source = this and actionCommand falling back to text. Note: the ActionEvent carries the cleartext (the Document's text), not the masked form — this matches JDK JTextField behaviour and keeps form-submit handlers working without a special-case for password fields.
  • setAction(Action) — narrow propagation per JDK JTextField: enabled / SHORT_DESCRIPTION / ACTION_COMMAND_KEY only.
See Also:
  • Constructor Details

    • SJPasswordField

      public SJPasswordField()
    • SJPasswordField

      public SJPasswordField(String text)
    • SJPasswordField

      public SJPasswordField(int columns)
    • SJPasswordField

      public SJPasswordField(String text, int columns)
    • SJPasswordField

      public SJPasswordField(Document doc, String text, int columns)
  • Method Details

    • validate

      public void validate()
      Visibility-widening override of PasswordField.validate() to satisfy ComponentMixin's public validate() contract. Delegates to super so Vaadin's input-validation behaviour is preserved.
      Specified by:
      validate in interface ComponentMixin
      Overrides:
      validate in class com.vaadin.flow.component.textfield.PasswordField
    • getEchoChar

      public char getEchoChar()
    • setEchoChar

      public void setEchoChar(char c)
      Set the echo character the L&F would paint. Fires nothing: the JDK's setter assigns, repaints and revalidates (SD_property_fanout_audit).

      Vaadin PasswordField has no server-side API to flip the underlying <input> element's type attribute — the masked-vs-cleartext visual is governed entirely client-side by the reveal button (eye icon). Since echoChar is a rendering input and nothing server-side renders text here, the write is pure state: it reaches no observable behaviour at all. Two divergence shapes:

      • Masked-vs-not — toggling echoChar=0 (JDK "show cleartext") on or off does not unmask the input visually. WARNs via SHelper.onUnimplemented(Object, String, Object...) per R_match_swing_errors sub-bucket (c) so migrators discover the no-op in the log. Migrated apps that toggle setEchoChar(0) for a "show password" UX should switch to PasswordField.setRevealButtonVisible(boolean) (default visible) and let the user click the eye icon.
      • Glyph — changing between two non-zero echo chars (default '*' → '#') is silently accepted. The browser renders <input type=password>'s native glyph regardless; documented divergence, not a WARN, since most apps stay on the default and the user-visible impact of "wrong masking glyph but still masked" is small.
    • echoCharIsSet

      public boolean echoCharIsSet()
      True iff echoChar != 0. JDK special case: 0 means "paint cleartext".
    • getPassword

      public char[] getPassword()
      Return a fresh char[] snapshot of the Document's contents. Caller is expected to zero the array after use so the cleartext password doesn't linger in the heap. Empty Document returns an empty array (matches JDK).
    • getColumns

      public int getColumns()
    • setColumns

      public void setColumns(int columns)
    • getHorizontalAlignment

      public int getHorizontalAlignment()
    • setHorizontalAlignment

      public void setHorizontalAlignment(int alignment)
    • addActionListener

      public void addActionListener(ActionListener l)
    • removeActionListener

      public void removeActionListener(ActionListener l)
    • getActionListeners

      public ActionListener[] getActionListeners()
    • claimsEnter

      public boolean claimsEnter()
      The SJTextField.claimsEnter() rule: a JPasswordField is a JTextField.
      Specified by:
      claimsEnter in interface EnterClaims.Claimant
    • fireActionPerformed

      protected void fireActionPerformed()
      Fire ActionEvent with source = this. actionCommand falls back to JTextComponentMixin.getText() — the same one-liner SJTextField carries, because JDK JPasswordField inherits JTextField's fallback unchanged.
    • setActionCommand

      public void setActionCommand(String command)
    • postActionEvent

      public void postActionEvent()
      Public synthesizer matching JDK — useful when not Enter-triggered.
    • getAction

      public Action getAction()
    • setAction

      public void setAction(Action a)
    • configurePropertiesFromAction

      protected void configurePropertiesFromAction(Action a)
      JDK JTextField's narrow Action property set: enabled / SHORT_DESCRIPTION / ACTION_COMMAND_KEY. No NAME propagation (would overwrite form data) or icons or mnemonics.
    • createActionPropertyChangeListener

      protected PropertyChangeListener createActionPropertyChangeListener(Action a)
    • actionPropertyChanged

      protected void actionPropertyChanged(Action a, String propertyName)
    • getUIClassID

      public String getUIClassID()
      Description copied from interface: JComponentMixin
      Deliberate no-op — L&F key.
      Specified by:
      getUIClassID in interface JComponentMixin
    • paramString

      protected String paramString()
      JDK JPasswordField.paramString chains JTextField's tail and appends the raw echoChar, unmasked. We follow the same shape; underlying Vaadin Component.toString is the honest host-side equivalent.
    • getAccessibleContext

      public AccessibleContext getAccessibleContext()