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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
foufou
Posts: 109
Registered: ‎11-15-2011
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 

Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
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
Please use plain text.
Trusted Contributor
foufou
Posts: 109
Registered: ‎11-15-2011
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 ??

Please use plain text.
Developer
simon_hain
Posts: 13,796
Registered: ‎07-29-2008
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
Please use plain text.
Trusted Contributor
foufou
Posts: 109
Registered: ‎11-15-2011
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);
	}

 

Please use plain text.
Developer
peter_strange
Posts: 17,698
Registered: ‎07-14-2008

Re: change the default color of focus

I recommend that you review the JavaDoc.

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
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!
Please use plain text.