Search code examples
java-metextfieldmidplcdui

Disable TextField in J2ME


Is it possible to dynamically make TextField element disabled and enabled during the run time in Java ME?


Solution

  • according to API documentation, setConstraints(TextField.UNEDITABLE) could do something like that:

    Sets the input constraints of the TextField...

    Note if you need to preserve contents and modifier flags, parameter passed to above method might require some tweaking, like

        setConstraints((getConstraints() & TextField.CONSTRAINT_MASK)
            | TextField.UNEDITABLE) // "disable" - set UNEDITABLE
    

    above to disable, and to enable back, something like:

        setConstraints((getConstraints() & TextField.CONSTRAINT_MASK))
            // "enable" - cleans up TextField.UNEDITABLE