Skip to main content

TextField , password mode ?

10 replies [Last post]
dwiardiirawan
Offline
Joined: 2007-07-09
Points: 0

i just curious, does TextField component support input mode like PASSWORD, NUMBER etc

passwordTxt = new TextField();
passwordTxt.setInputMode( ??? );

how can i make my passwordTxt component's input in password mode ?

or password mode only can apply to TextArea component ?

thnx u

dwi ardi irawan
http://dwiardiirawan.blogspot.com

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gopimano
Offline
Joined: 2010-12-01
Points: 0

JPasswordField in javax.swing is a simple solution for this problem

otto_burdiga
Offline
Joined: 2008-09-16
Points: 0

[b]Additional example :[/b]

final Form f = new Form();

Hashtable [b]num[/b] = new Hashtable();
num.put(new Integer('*'), "." );
num.put(new Integer('0'), "0" );
num.put(new Integer('#'), "," );
num.put(new Integer('9'), "9" );
num.put(new Integer('8'), "8" );
num.put(new Integer('7'), "7" );
num.put(new Integer('6'), "6" );
num.put(new Integer('5'), "5" );
num.put(new Integer('4'), "4" );
num.put(new Integer('3'), "3" );
num.put(new Integer('2'), "2" );
num.put(new Integer('1'), "1" );

Hashtable [b]bin[/b] = new Hashtable();
bin.put(new Integer('0'), "0" );
bin.put(new Integer('1'), "1" );

Hashtable [b]hex[/b] = new Hashtable();
hex.put(new Integer('9'), "9" );
hex.put(new Integer('8'), "8" );
hex.put(new Integer('7'), "7" );
hex.put(new Integer('6'), "6F" );
hex.put(new Integer('5'), "5E" );
hex.put(new Integer('4'), "4D" );
hex.put(new Integer('3'), "3C" );
hex.put(new Integer('2'), "2B" );
hex.put(new Integer('1'), "1A" );
hex.put(new Integer('0'), "0" );

TextField TextField_W = new TextField(9);
// java.util.Hashtable value: [b]num[/b] | [b]bin[/b] | [b]hex[/b]
// java.lang.String name : "[b]num[/b]"|"[b]bin[/b]"|"[b]hex[/b]"
TextField_W.addInputMode("[b]num[/b]", [b]num[/b], false);
TextField_W.setInputMode("[b]num[/b]");
f.addComponent(TextField_W);

ashnee
Offline
Joined: 2009-07-20
Points: 0

Can anyone tell me how to create a TextField Input mode such that the TextField accepts only characters (String), or a combination of characters and numbers but not number alone. Can anyone tell me how to do that?

vprise
Offline
Joined: 2003-11-07
Points: 0

http://forums.java.net/jive/thread.jspa?messageID=317840
http://forums.java.net/jive/message.jspa?messageID=342229

Use addInputMode() followed by setInputModeOrder()
From the javadoc:The key for the hashtable is an Integer keyCode and the value is a String containing the characters to toggle between for the given keycode

Shai Almog

Hi,
password mode works pretty much as you would expect:
myTextField.setConstraint(TextArea.PASSWORD);

Number input mode is a bit more complex and relates to the different
approaches between MIDP input and LWUIT. The text field performs its
own input using the "input mode" which doesn't respect the input
constraint (other than password), the input constraint (calls to
setConstraint method) will only effect the "native" MIDP text box
(when selecting the T9 softkey).
To change the input mode for the text field you need to use a
separate set of API's: setInputMode, addInputMode, setInputModeOrder
etc...

So to support number only input do the following:
myTextField.setConstraint(TextArea.NUMERIC);
myTextField.setInputModeOrder(new String[] {"123"});

Hope this helps.
Shai.

> i just curious, does TextField component support input mode like
> PASSWORD, NUMBER etc
>
> passwordTxt = new TextField();
> passwordTxt.setInputMode( ??? );
>
> how can i make my passwordTxt component's input in password mode ?
>
> or password mode only can apply to TextArea component ?
>
>
> thnx u
>
> dwi ardi irawan
> http://dwiardiirawan.blogspot.com
> [Message sent by forum member 'dwiardiirawan' (dwiardiirawan)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284501
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

seik
Offline
Joined: 2008-07-03
Points: 0

I tried:
TextField myTextField = new TextField();
myTextField.setConstraint(TextArea.NUMERIC);
myTextField.setInputModeOrder(new String[] {"123"});

but even so the textfield keeps accepting nonnumeric chars like "a,B.%¨"....

is it my mistake or is this function not implemented yet?

Shai Almog

There is a bug in the current text field that requires an additional
call to (besides the other two command):
myTextField.setInputMode("123");

This won't be necessary in the next drop.

Thanks,
Shai.

> I tried:
> TextField myTextField = new TextField();
> myTextField.setConstraint(TextArea.NUMERIC);
> myTextField.setInputModeOrder(new String[] {"123"});
>
> but even so the textfield keeps accepting nonnumeric chars like
> "a,B.%¨"....
>
> is it my mistake or is this function not implemented yet?
> [Message sent by forum member 'seik' (seik)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284741
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

seik
Offline
Joined: 2008-07-03
Points: 0

now its working ^^
I noticed an "addInputMode(String,Hashtable,boolean)" function on the form.
does this function create a new InputMode, so that I can use it like the "123" InputMode ?
if so, how should I create the hashtable?
I tried {
Hashtable ht = new Hashtable();
ht.put("0", new Integer(0));
ht.put("1", new Integer(1));
ht.put("2", new Integer(2));
ht.put("3", new Integer(3));
ht.put("4", new Integer(4));
ht.put("5", new Integer(5));
} and {
Hashtable ht = new Hashtable();
ht.put("0", "0");
ht.put("1", "1");
ht.put("2", "2");
ht.put("3", "3");
ht.put("4", "4");
ht.put("5", "5");
} but it didnt work T_T

(by now you must be wanting to kill me or at least make me pay for the leasons XD...ops I shouldnt give you such ideas )
thanks for your time and patience

Shai Almog

Try:
ht.put(new Integer('1'), "ABC"));
ht.put(new Integer('2'), "DEF"));

etc...

I don't want to kill anyone inquisitive who actually tries
understanding the API ;-)
Thanks,
Shai.

> now its working ^^
> I noticed an "addInputMode(String,Hashtable,boolean)" function on
> the form.
> does this function create a new InputMode, so that I can use it
> like the "123" InputMode ?
> if so, how should I create the hashtable?
> I tried {
> Hashtable ht = new Hashtable();
> ht.put("0", new Integer(0));
> ht.put("1", new Integer(1));
> ht.put("2", new Integer(2));
> ht.put("3", new Integer(3));
> ht.put("4", new Integer(4));
> ht.put("5", new Integer(5));
> } and {
> Hashtable ht = new Hashtable();
> ht.put("0", "0");
> ht.put("1", "1");
> ht.put("2", "2");
> ht.put("3", "3");
> ht.put("4", "4");
> ht.put("5", "5");
> } but it didnt work T_T
>
> (by now you must be wanting to kill me or at least make me pay for
> the leasons XD...ops I shouldnt give you such ideas )
> thanks for your time and patience
> [Message sent by forum member 'seik' (seik)]
>
> http://forums.java.net/jive/thread.jspa?messageID=284764
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net

seik
Offline
Joined: 2008-07-03
Points: 0

thanks!
its working now ^^
till next question. lol