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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

drawFocus in ListField

Hi,

 

I have a problem to use drawFocus() in ListField.  Should I call clear() and super.paint(g) in drawFocus?

Because I'm not getting what I want.

protected void drawFocus(Graphics g, boolean on) { if (g.getBackgroundColor() != 3098850) { XYRect xy = g.getClippingRect(); g.setBackgroundColor(0xe86e48); g.fillRect(xy.x,xy.y,xy.width,xy.height); g.clear(); } super.paint(g); }

 

BlackBerry Development Advisor
Posts: 15,885
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: drawFocus in ListField

Can you describe your problem and what you want to achieve?  You may also want to have a look at these ListField samples.

 

How To - Create a colour ListField
Article Number: DB-00472

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

 

How To - Create a ListField with check boxes 
Article Number: DB-00471

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: drawFocus in ListField

Mark,

 

What I want are:

 

1) I want to change Focus color to my own.

2) I want to have different colors for evev and odd row, i.e., even row - light blue and odd row - light grey.

 

I tried to use drawFocus with setBackground for focus but no luck.

I'll see the examples you sent.

 

Thanks,

DK

BlackBerry Development Advisor
Posts: 15,885
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: drawFocus in ListField

The sample in the "Create a colour ListField" should help with what you are trying to do.  You'll just need to adjust the colours.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: drawFocus in ListField

Mark,

 

This helps me a lot but I can not change highlight color.

 

Thanks,

DK.

BlackBerry Development Advisor
Posts: 15,885
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: drawFocus in ListField

You'll need to add support for this in the sample.  Basically you need to check if startLine equals curSelected to determine if the current line being drawn is the one to highlight.  Then, set your desired colour, call graphics.fillRect to create the highlight rectangle, change the colour back to the text colour and draw the text.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Posts: 141
Registered: ‎08-06-2008
My Device: Not Specified

Re: drawFocus in ListField

Hi Mark,

 

Thanks for your help below is the code I followed the example you recommended.

 

public void paint(Graphics g) { int[] e_cols = new int[]{EVEN_COLOR,EVEN_COLOR,EVEN_COLOR,EVEN_COLOR}; int[] o_cols = new int[]{ODD_COLOR,ODD_COLOR,ODD_COLOR,ODD_COLOR}; XYRect xy = g.getClippingRect(); if(xy.y < 0)

{ throw new IllegalStateException("Clipping rectangle is wrong.");

} int rowHeight = getRowHeight(); int curSelected; int startLine = xy.y / rowHeight; int y = startLine * rowHeight; int endLine = (xy.y + xy.height - 1) / rowHeight; endLine = Math.min(endLine, getSize() - 1); int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight}; int[] xInds = new int[]{0, getPreferredWidth(), getPreferredWidth(), 0}; Font _font;

 

if (hasFocus) { curSelected = getSelectedIndex(); } else { curSelected = -1; } //Setup the data used for drawing. ListFieldCallback callBack = this.getCallback(); for(; startLine <= endLine; ++startLine) { String text =(String)callBack.get(this, startLine); String [] subStr; String phone = null; subStr = Utils.split(text,"|"); //returned phone number and option phone = subStr[4] + ", Distance:" + subStr[5]+ "mi, Rate:" +subStr[6]; if (subStr[subStr.length-1].trim().equals("1")) optionImg = Bitmap.getBitmapResource("option_1.png"); if (subStr[subStr.length-1].trim().equals("2")) optionImg = Bitmap.getBitmapResource("option_2.png"); if (subStr[subStr.length-1].trim().equals("3")) optionImg = Bitmap.getBitmapResource("option_3.png"); if (startLine % 2 == 0 && startLine != curSelected) { //if (g.getBackgroundColor() != 3098850) g.setColor(LIGHT_TEXT); g.drawShadedFilledPath(xInds, yInds, null, o_cols, null); _font = Utils.BBMillBank(12); g.setColor(DARK_TEXT); g.setFont(_font); g.drawText(subStr[0], 2, y+1); _font = Utils.BBMillBank(Font.PLAIN, 12); g.setColor(0x333333); g.setFont(_font); g.drawText(subStr[1] + " " + subStr[2]+ ", " + subStr[3], 2, y+listHeight+1); _font = Utils.BBMillBank(Font.PLAIN, 12); g.setColor(0xe86e28); g.setFont(_font); g.drawText(phone, 2, y + 2*listHeight+1); //g.setColor(DARK_TEXT); g.drawBitmap(Display.getWidth()-optionImg.getWidth(),

startLine*optionImg.getHeight(),

optionImg.getWidth(),

optionImg.getHeight(),

optionImg, 0,0);

g.setColor(DARK_TEXT); g.drawRect(0, startLine*optionImg.getHeight(), Display.getWidth(), optionImg.getHeight());

g.drawRect(Display.getWidth()-optionImg.getWidth(),

startLine*optionImg.getHeight(),

optionImg.getWidth(), optionImg.getHeight());

} else { //if (g.getBackgroundColor() != EVEN_COLOR) // g.drawShadedFilledPath(xInds, yInds, null, e_cols, null); _font = Utils.BBMillBank(12); g.setColor(DARK_TEXT); g.setFont(_font); g.drawText(subStr[0], 2, y+1); _font = Utils.BBMillBank(Font.PLAIN, 12); g.setColor(0x333333); g.setFont(_font); g.drawText(subStr[1] + " " + subStr[2]+ ", " + subStr[3], 2, y+listHeight+1); _font = Utils.BBMillBank(Font.PLAIN, 12); g.setColor(0xe86e28); g.setFont(_font); g.drawText(phone, 2, y + 2*listHeight+1); g.drawBitmap(Display.getWidth()-optionImg.getWidth(),

startLine*optionImg.getHeight(),

optionImg.getWidth(), optionImg.getHeight(), optionImg, 0,0); g.setColor(DARK_TEXT); g.drawRect(0, startLine*optionImg.getHeight(), Display.getWidth(), optionImg.getHeight());

g.drawRect(Display.getWidth()-optionImg.getWidth(),

startLine*optionImg.getHeight(), optionImg.getWidth(), optionImg.getHeight());

} y += rowHeight; yInds[0] = y; yInds[1] = yInds[0]; yInds[2] = y + rowHeight; yInds[3] = yInds[2];

} }

 

 

Screen shot

 

Above is output.

What I want to do is that I want to change highlight color to other color.

I tried several way but no luck.

 

Please help me.

 

Thanks,

DK.

Highlighted
BlackBerry Development Advisor
Posts: 15,885
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: drawFocus in ListField

You need another block in the if (startLine... block.  The first statement remains the same, then add an else if that checks if startLine is equal to currentRow.  From there you can draw a rectangle in the colour of your choice (and then draw the rest of your list).  The rest of the code in the if and else sections could remain the same.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.