04-13-2009 04:15 PM
I have a TextField and after setting its contents (with setText()) I want to select part of it. How can this be done from the TextField API?
Solved! Go to Solution.
04-14-2009 01:10 AM - edited 04-14-2009 02:23 AM
Does it mean, you want to higlight a part of the text field? - You can paint method of TextField.
You want a substring of the text which is been set on the screen? - Get the text of Field and get the substring out of it depending on your requirement.
04-14-2009 02:13 AM
I guess when you are adding BasicEditField on your screen then application menu is automatically get added with option SELECT.
You can use this option.
I guess you are using MainScreen.
04-14-2009 02:16 AM
04-14-2009 09:58 AM
1) Yes, I'm asking about how to select text in a TextField, using the API, not how to do it with the trackwheel and context menu.
2) "Selecting" text in a TextField means to (a) highlight the selected text, (b) if the user then uses the menu to copy, the selected text is copied, and (c) if the user types, the selected text is replaced.
So now that we understand what needs to be done, how is it done?
04-14-2009 10:30 AM
04-14-2009 11:04 AM
Is there any specific reason why you wnat to do this using java API beacuse every thing you mention can be done using options provided in the menu.
04-14-2009 11:49 AM
First of all, anything that the user can do, must be available to be done programatically. That is just good (and standard) API development practice.
In this particular case, I fill a text field with a value that I need the user to change. To be specific, I fill the text field with "Enter value here" (or something like that). If this text is not selected, the user must explicitely erase (backspace over, or type over) my text. If the text is selected, the first character they type will erase my text.
04-15-2009 02:27 AM
04-15-2009 02:37 AM
you can also overwrite the custom behaviour of the field, which would be a more elegant solution. for example you could overwrite onFocus and delete the pre-set text. or keychar and delete it when the user types something. etc.
I personally accept the last solution provided by Simon.