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
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

change the default color of focus

[ Edited ]

Hello,

 

I want to change the blue color of focus on items. I use this code to create items on screens.

 

VerticalFieldManager manager = (VerticalFieldManager) getMainManager();


        gfm = new GridFieldManager(rows, columns, GridFieldManager.FIXED_SIZE);

        manager.add(gfm);
        int columnWidth = (Display.getWidth() / columns)
                - gfm.getColumnPadding();
        for ( i = 0; i < columns; i++) {
            gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
        }

        BitmapField[] images = new BitmapField[6];
        EncodedImage Icon = null;
        for (i = 0; i < 6; i++) {


                Icon = EncodedImage
                        .getEncodedImageResource("img/HOME.png");



            images[i] = new BitmapField(Icon.getBitmap(), Field.FIELD_HCENTER
                    | Field.FIELD_VCENTER | Field.FOCUSABLE) {


                protected void layout(int width, int height) {
                    setExtent(getPreferredWidth()+20, getPreferredHeight() + 15);

                    }



                protected void paint(Graphics graphics) {

                    super.paint(graphics);


                     graphics.drawText("text", 0,
                     getBitmapHeight(), 2, getBitmapWidth() + 20);


                }

            };

            gfm.setPadding(10, 0, 0, 0);
            gfm.setRowPadding(20);
            images[i].setPadding(20, 10, 5, 10);
            gfm.add(images[i]);


        }

    }

 

 Thanks 

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: change the default color of focus

please format your code correctly.

you can overwrite drawFocus to change the focus drawing.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: change the default color of focus

Soory about the format I edit my code

how can I use the method drawFocus in my code ??

Developer
Posts: 16,997
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: change the default color of focus

override it, similar as you did with paint
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Trusted Contributor
Posts: 109
Registered: ‎11-15-2011
My Device: blackberry 9800
My Carrier: beginner developer

Re: change the default color of focus

I use this method but nothing happen

 

protected void drawFocus(Graphics graphics, boolean on) {
	
		graphics.setBackgroundColor(Color.RED);
		
		
		super.drawFocus(graphics, on);
	}

 

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

Re: change the default color of focus

I recommend that you review the JavaDoc.

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: change the default color of focus

Take a look at Field.setBackground method with two parameters: int visual, Background background. The visual parameter can be one of the VISUAL_STATE_... constants, also defined in Field class. Define the desired background for VISUAL_STATE_FOCUS (and VISUAL_STATE_NORMAL, if necessary). This way you won't even have to override drawFocus - the framework will take care of it for you.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!