Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.
javax.swing.text

Class DefaultFormatter

  • All Implemented Interfaces:
    Serializable, Cloneable
    Direct Known Subclasses:
    InternationalFormatter, MaskFormatter

    public class DefaultFormatter
    extends JFormattedTextField.AbstractFormatter
    implements Cloneable, Serializable
    DefaultFormatter formats aribtrary objects. Formatting is done by invoking the toString method. In order to convert the value back to a String, your class must provide a constructor that takes a String argument. If no single argument constructor that takes a String is found, the returned value will be the String passed into stringToValue.

    Instances of DefaultFormatter can not be used in multiple instances of JFormattedTextField. To obtain a copy of an already configured DefaultFormatter, use the clone method.

    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.

    Since:
    1.4
    See Also:
    JFormattedTextField.AbstractFormatter
    • Constructor Detail

      • DefaultFormatter

        public DefaultFormatter()
        Creates a DefaultFormatter.
    • Method Detail

      • install

        public void install(JFormattedTextField ftf)
        Installs the DefaultFormatter onto a particular JFormattedTextField. This will invoke valueToString to convert the current value from the JFormattedTextField to a String. This will then install the Actions from getActions, the DocumentFilter returned from getDocumentFilter and the NavigationFilter returned from getNavigationFilter onto the JFormattedTextField.

        Subclasses will typically only need to override this if they wish to install additional listeners on the JFormattedTextField.

        If there is a ParseException in converting the current value to a String, this will set the text to an empty String, and mark the JFormattedTextField as being in an invalid state.

        While this is a public method, this is typically only useful for subclassers of JFormattedTextField. JFormattedTextField will invoke this method at the appropriate times when the value changes, or its internal state changes.

        Overrides:
        install in class JFormattedTextField.AbstractFormatter
        Parameters:
        ftf - JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.
      • setCommitsOnValidEdit

        public void setCommitsOnValidEdit(boolean commit)
        Sets when edits are published back to the JFormattedTextField. If true, commitEdit is invoked after every valid edit (any time the text is edited). On the other hand, if this is false than the DefaultFormatter does not publish edits back to the JFormattedTextField. As such, the only time the value of the JFormattedTextField will change is when commitEdit is invoked on JFormattedTextField, typically when enter is pressed or focus leaves the JFormattedTextField.
        Parameters:
        commit - Used to indicate when edits are commited back to the JTextComponent
      • getCommitsOnValidEdit

        public boolean getCommitsOnValidEdit()
        Returns when edits are published back to the JFormattedTextField.
        Returns:
        true if edits are commited after evey valid edit
      • setOverwriteMode

        public void setOverwriteMode(boolean overwriteMode)
        Configures the behavior when inserting characters. If overwriteMode is true (the default), new characters overwrite existing characters in the model.
        Parameters:
        overwriteMode - Indicates if overwrite or overstrike mode is used
      • getOverwriteMode

        public boolean getOverwriteMode()
        Returns the behavior when inserting characters.
        Returns:
        true if newly inserted characters overwrite existing characters
      • setAllowsInvalid

        public void setAllowsInvalid(boolean allowsInvalid)
        Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException). It is often convenient to allow the user to temporarily input an invalid value.
        Parameters:
        allowsInvalid - Used to indicate if the edited value must always be valid
      • getAllowsInvalid

        public boolean getAllowsInvalid()
        Returns whether or not the value being edited is allowed to be invalid for a length of time.
        Returns:
        false if the edited value must always be valid
      • setValueClass

        public void setValueClass(Class<?> valueClass)
        Sets that class that is used to create new Objects. If the passed in class does not have a single argument constructor that takes a String, String values will be used.
        Parameters:
        valueClass - Class used to construct return value from stringToValue
      • getValueClass

        public Class<?> getValueClass()
        Returns that class that is used to create new Objects.
        Returns:
        Class used to constuct return value from stringToValue
      • stringToValue

        public Object stringToValue(String string)
                             throws ParseException
        Converts the passed in String into an instance of getValueClass by way of the constructor that takes a String argument. If getValueClass returns null, the Class of the current value in the JFormattedTextField will be used. If this is null, a String will be returned. If the constructor thows an exception, a ParseException will be thrown. If there is no single argument String constructor, string will be returned.
        Specified by:
        stringToValue in class JFormattedTextField.AbstractFormatter
        Parameters:
        string - String to convert
        Returns:
        Object representation of text
        Throws:
        ParseException - if there is an error in the conversion

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 04/03/2020 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-rf-javax/swing/text/defaultformatter.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur Deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.

Inhoudsopgave Haut