Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.
javax.swing

Class JPasswordField

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, SwingConstants

    public class JPasswordField
    extends JTextField
    JPasswordField is a lightweight component that allows the editing of a single line of text where the view indicates something was typed, but does not show the original characters. You can find further information and examples in How to Use Text Fields, a section in The Java Tutorial.

    JPasswordField is intended to be source-compatible with java.awt.TextField used with echoChar set. It is provided separately to make it easier to safely change the UI for the JTextField without affecting password entries.

    NOTE: By default, JPasswordField disables input methods; otherwise, input characters could be visible while they were composed using input methods. If an application needs the input methods support, please use the inherited method, enableInputMethods(true).

    Warning: Swing is not thread safe. For more information see Swing's Threading Policy.

    Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

    • Constructor Detail

      • JPasswordField

        public JPasswordField()
        Constructs a new JPasswordField, with a default document, null starting text string, and 0 column width.
      • JPasswordField

        public JPasswordField(String text)
        Constructs a new JPasswordField initialized with the specified text. The document model is set to the default, and the number of columns to 0.
        Parameters:
        text - the text to be displayed, null if none
      • JPasswordField

        public JPasswordField(int columns)
        Constructs a new empty JPasswordField with the specified number of columns. A default model is created, and the initial string is set to null.
        Parameters:
        columns - the number of columns >= 0
      • JPasswordField

        public JPasswordField(String text,
                      int columns)
        Constructs a new JPasswordField initialized with the specified text and columns. The document model is set to the default.
        Parameters:
        text - the text to be displayed, null if none
        columns - the number of columns >= 0
      • JPasswordField

        public JPasswordField(Document doc,
                      String txt,
                      int columns)
        Constructs a new JPasswordField that uses the given text storage model and the given number of columns. This is the constructor through which the other constructors feed. The echo character is set to '*', but may be changed by the current Look and Feel. If the document model is null, a default one will be created.
        Parameters:
        doc - the text storage to use
        txt - the text to be displayed, null if none
        columns - the number of columns to use to calculate the preferred width >= 0; if columns is set to zero, the preferred width will be whatever naturally results from the component implementation
    • Method Detail

      • getEchoChar

        public char getEchoChar()
        Returns the character to be used for echoing. The default is '*'. The default may be different depending on the currently running Look and Feel. For example, Metal/Ocean's default is a bullet character.
        Returns:
        the echo character, 0 if unset
        See Also:
        setEchoChar(char), echoCharIsSet()
      • setEchoChar

        public void setEchoChar(char c)
        Sets the echo character for this JPasswordField. Note that this is largely a suggestion, since the view that gets installed can use whatever graphic techniques it desires to represent the field. Setting a value of 0 indicates that you wish to see the text as it is typed, similar to the behavior of a standard JTextField.
        Parameters:
        c - the echo character to display
        See Also:
        echoCharIsSet(), getEchoChar()
      • echoCharIsSet

        public boolean echoCharIsSet()
        Returns true if this JPasswordField has a character set for echoing. A character is considered to be set if the echo character is not 0.
        Returns:
        true if a character is set for echoing
        See Also:
        setEchoChar(char), getEchoChar()
      • cut

        public void cut()
        Invokes provideErrorFeedback on the current look and feel, which typically initiates an error beep. The normal behavior of transferring the currently selected range in the associated text model to the system clipboard, and removing the contents from the model, is not acceptable for a password field.
        Overrides:
        cut in class JTextComponent
        See Also:
        Toolkit.getSystemClipboard(), Clipboard
      • copy

        public void copy()
        Invokes provideErrorFeedback on the current look and feel, which typically initiates an error beep. The normal behavior of transferring the currently selected range in the associated text model to the system clipboard, and leaving the contents from the model, is not acceptable for a password field.
        Overrides:
        copy in class JTextComponent
        See Also:
        Toolkit.getSystemClipboard(), Clipboard
      • getText

        @Deprecated
        public String getText()
        Deprecated. As of Java 2 platform v1.2, replaced by getPassword.
        Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException.

        For security reasons, this method is deprecated. Use the * getPassword method instead.

        Overrides:
        getText in class JTextComponent
        Returns:
        the text
        See Also:
        JTextComponent.setText(java.lang.String)
      • getText

        @Deprecated
        public String getText(int offs,
                                int len)
                       throws BadLocationException
        Deprecated. As of Java 2 platform v1.2, replaced by getPassword.
        Fetches a portion of the text represented by the component. Returns an empty string if length is 0.

        For security reasons, this method is deprecated. Use the getPassword method instead.

        Overrides:
        getText in class JTextComponent
        Parameters:
        offs - the offset >= 0
        len - the length >= 0
        Returns:
        the text
        Throws:
        BadLocationException - if the offset or length are invalid
      • getPassword

        public char[] getPassword()
        Returns the text contained in this TextComponent. If the underlying document is null, will give a NullPointerException. For stronger security, it is recommended that the returned character array be cleared after use by setting each character to zero.
        Returns:
        the text
      • paramString

        protected String paramString()
        Returns a string representation of this JPasswordField. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.
        Overrides:
        paramString in class JTextField
        Returns:
        a string representation of this JPasswordField
      • getAccessibleContext

        public AccessibleContext getAccessibleContext()
        Returns the AccessibleContext associated with this JPasswordField. For password fields, the AccessibleContext takes the form of an AccessibleJPasswordField. A new AccessibleJPasswordField instance is created if necessary.
        Specified by:
        getAccessibleContext in interface Accessible
        Overrides:
        getAccessibleContext in class JTextField
        Returns:
        an AccessibleJPasswordField that serves as the AccessibleContext of this JPasswordField

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/swing/jpasswordfield.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.

Referenzen

  1. Zeigen Sie - html-Dokument Sprache des Dokuments:fr Manuel PHP : https://docs.oracle.com

Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.

Inhaltsverzeichnis Haut