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
Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified
Accepted Solution

style text differently in listFied

I have craeted a listfield that allows two lines of text to be displayed for each row and also display a block of colour.

// set font
FontFamily font;
Font intFont = null;

try{
font = FontFamily.forName("BBCasual");
}catch(ClassNotFoundException e){
font = Font.getDefault().getFontFamily();
}

intFont = font.getFont(Font.PLAIN,16);

..................

graphics.setColor(Integer.parseInt(_colorStr[index])); graphics.clear(); graphics.setColor(Integer.parseInt(_colorStr[index])); graphics.fillRect(0,y,40,40); graphics.drawBitmap(1, y + offsetY, icon.getWidth(), icon.getHeight(), icon, 0, 0); graphics.drawBitmap(screenWidth - 40, y + offsetY + 10, icon.getWidth(), icon.getHeight(), arrow, 0, 0); graphics.setFont(intFont); // display Line 1 of Text graphics.drawText(_nameStr[index] , icon.getWidth() + 8, y,(DrawStyle.LEFT + DrawStyle.ELLIPSIS + DrawStyle.TOP), width); //display Line 2 of Text graphics.drawText("£" + _valueStr[index], icon.getWidth() + 8, y+20,(DrawStyle.LEFT+DrawStyle.ELLIPSIS+DrawStyle.TOP), width);

I have three problems. 

 

1) When I set the color for the rectangle that I am drawing it changes the color of the text.

2) I would like to have a different style for each line, line 1 I would like to be bold.

3) Is it possible to set a border around each row of the listField?

 

Any help with this would be much appreciated!

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: style text differently in listFied

"1) When I set the color for the rectangle that I am drawing it changes the color of the text"

Correct, there is only one foreground color.  Change it to something else before your draw your text

 

"2) I would like to have a different style for each line, line 1 I would like to be bold."

Why not!  Just change the font you use before the associated drawText

 

"3) Is it possible to set a border around each row of the listField?"

Sure.  use drawRect

 

I presume the code that you have shown us is in your drawListRow method.

Developer
Posts: 129
Registered: ‎09-21-2009
My Device: Not Specified

Re: style text differently in listFied

Cheers, I think I have finally twigged on how it works, simple when you think about it.  Thank you.