Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

AttributedString vs DrawText on aTextField, anyone used it ?

Interesting finding.

 

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?



"Listen carefully, I shall say this only once"
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: AttributedString vs DrawText on aTextField, anyone used it ?

Hi,

 

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.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: AttributedString vs DrawText on aTextField, anyone used it ?

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.



"Listen carefully, I shall say this only once"
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: AttributedString vs DrawText on aTextField, anyone used it ?

Hi,

 

May be you can use width of the bitmap to determine it position.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: AttributedString vs DrawText on aTextField, anyone used it ?

Maybe I was not clear enough...

Here's what I had in mind:

 

 

Initial state:

 

+-------+

| Input:|

+-------+

 

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 ?

 

Any suggestions?

 



"Listen carefully, I shall say this only once"
Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: AttributedString vs DrawText on aTextField, anyone used it ?

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.

 

Rab

Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: AttributedString vs DrawText on aTextField, anyone used it ?

Hi,

 

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.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: AttributedString vs DrawText on aTextField, anyone used it ?

Thanks Rab & Rajat.

 

I will try first Rab's approach (looks cleaner) and then Rajat's.

 

@Rajat

 

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

 

KR

 

Myraddin



"Listen carefully, I shall say this only once"