08-04-2009 05:26 AM
While looking for a way to draw an icon inside a textField I stumbled upon its drawText() method.
The intersting thing is the description (see TextField class) of the drawText():
"...May be overridden by derived classes to provide special behaviour - highly discouraged, use AttributedString instead (due to open in 4.2.2). ..."
Well, how can one use the AttributedString?
BTW, anyone has a suggestion how to draw an icon which will always be position to the right of the textField. The user will input text in a textfield and the icon should move right-left to accomodate the text length change?
08-04-2009 06:36 AM
I have not done such thing, but i think you can drop an image in paint().
Override the paint() of textField and use g.drawBitmap to draw an image.
08-04-2009 06:40 AM
Will try, thx.
But in that case it's a bit harder to determine the exact position of the bitmap.
Thank you for the hint.
08-04-2009 06:46 AM
May be you can use width of the bitmap to determine it position.
08-04-2009 07:33 AM
Maybe I was not clear enough...
Here's what I had in mind:
Now the User inputs a few characters:
| Input:aaa || X |
Where X represents the image.
Later on this might look like:
| ...12345678901234567890123456789 || X |
Using the elipsis property.
The behaviour should, in fact, be similar to the BB's Phone log (the X bitmap is, in that case, the green phone icon)
Should I override paint, drawText or use (how?) the AttributedString ?
08-04-2009 11:11 AM
Can this be done using a FlowManager that contains the inputField and the BitmapField? You may add some logic to set the width of the inputField after each entered character.
I did not try it, but just a different thought.
08-04-2009 11:25 AM
Just a thought,you can try this
Say your screen width is 320 pixel.
Initial size of your textField is 20 Pixel and width of bitmap is 20 Pixel then when you add say 1 character ,suppose width of this text is 5 pixel then move your bitmap by position i.e if image was previously drawn at (21,0) xy-cordinate now it will drawn at (25,0) xy-cordinate.
08-06-2009 04:43 AM
Thanks Rab & Rajat.
I will try first Rab's approach (looks cleaner) and then Rajat's.
It seems a bit tricky to do this as the paint/draw text methods don't have access to the getAdvance() method nor the string being drawn...
Of course it's doable... but not in an easy (simple) manner.
Thanks again for your inputs