Textfield Uppercase

48 views
Skip to first unread message

cblanken...@gmail.com

unread,
Dec 3, 2015, 9:08:55 AM12/3/15
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans
Desktop OS
Simulator
Device

I need to allow the user to use alpha, numeric, and symbols but need to uppercase any provided alpha values to uppercase.

1. is there a way to force a textfield to uppercase regardless of if it is being entered in as lowercase? if so examples?
2. is there a way for a textfield on loss of focus to update the data that has changed to uppercase? also if so examples?

Thank you.

Diamond

unread,
Dec 3, 2015, 9:54:13 AM12/3/15
to CodenameOne Discussions, cblanken...@gmail.com
Hi,

myTextfield.setInputMode("ABC");

could help, but you can't change textfield value to anything else as you type, it will trigger a stackOverflowException. 

You can add a doneListener to your textfield to change it's value to Caps after input is completed.

cblanken...@gmail.com

unread,
Dec 3, 2015, 10:08:43 AM12/3/15
to CodenameOne Discussions, cblanken...@gmail.com
have tried setInputMode("ABC") that does not appear to work on my device. doneListener will only work on supported platforms.

Shai Almog

unread,
Dec 4, 2015, 12:28:29 AM12/4/15
to CodenameOne Discussions, cblanken...@gmail.com
Hi,
in the action event for the text field just invoke tf.setText(tf.getText().toUpperCase());

The input mode code is only relevant to older devices that work with lightweight input.

Diamond

unread,
Dec 4, 2015, 1:26:55 AM12/4/15
to CodenameOne Discussions, cblanken...@gmail.com
As Shai suggested, actionEvent got triggered once the Textfield loses focus. You can invoke it as follows:

        txtChangeToUpper.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                txtChangeToUpper.setText(txtChangeToUpper.getText().toUpperCase());
            }
        });


Reply all
Reply to author
Forward
0 new messages