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

Posts: 88
Registered: ‎05-24-2009
My Device: Not Specified

ListField drawFocus Question



I am overriding drawFocus in ListField, and attempting to paint on the background after the drawListRow call (drawFocus seems to be called after drawListRow). Now if i do any drawing it draws on top of the stuff drawn in drawListRow. The default drawFocus implementation somehow manages to select the background without overwriting the foreground.


Any ideas?


Best Regards.


Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: ListField drawFocus Question

In your drawFocus override, just call

getCallback().drawListRow(this, graphics, getSelectedIndex(), rect.y, rect.width);

after painting the background.

Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Posts: 19
Registered: ‎01-18-2011
My Device: Bold 9000
My Carrier: at&t

Re: ListField drawFocus Question

this works, I post the code for others


ListField's drawFocus method


protected void drawFocus(Graphics graphics, boolean on) {
        XYRect rect = new XYRect();
        Logger.debug("x,y,width,height:" + rect.x + "," + rect.y + ", " + rect.width + "," + rect.height);

        // draw the background
        boolean oldDrawStyleFocus = graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS);
        int oldColour = graphics.getColor();
        try {
            if (on) {
                graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, true);
            try {
                graphics.fillRect(rect.x, rect.y, rect.width, rect.height);
            } finally {
            drawListRow(this, graphics, getSelectedIndex(), rect.y, rect.width);
        } finally {
            graphics.setDrawingStyle(Graphics.DRAWSTYLE_FOCUS, oldDrawStyleFocus);



New Developer
Posts: 137
Registered: ‎02-04-2010
My Device: Tour 9630
My Carrier: verizon

Re: ListField drawFocus Question

golden example code.