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
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified
Accepted Solution

White Box around Rounded Button

I've been stuck on this for a while, as i've been playing about with buttons.

 

What i have is a single button, button where i have rounded corners using this method within the paint method. 

 

 

    

g.drawShadedFilledPath(xPts, yPts, PATH_POINT_TYPES, PATH_GRADIENT, null);
    g.setColor(BORDER_COLOR);
    g.drawRoundRect(0, 0, width, height, CURVE_X * 2, CURVE_Y * 2);

 

 

The button is drawn fine, but there is white rectangle that seems to surround the button. i have tried setting the background colour via getMainManager(), also setting the background colour on the button, with no joy.

 

Has anyone come across this...

 

right my details are as follows :

 

my Eclipse tells me the following

BB Java Plugin 1.1.2

BB Java SDK 5.0

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

Re: White Box around Rounded Button

I think I do this, and the background color is just determined by the manager.  Do you set a background color for the button, to say white and do something like

graphics.clear();

anywhere, as that will give you a white background for anything you don't paint.  Also I suggest you return the color of the graphics context to what it was on entry to paint before you exit or call super.paint().

 

Anyway, if this doesn't help, I think we might need to see more of your code.  .

Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Re: White Box around Rounded Button

I set the graphics background to the colour i set for the button. maybe this isn't being set. i debugged the code and the value is being set within the paint method, but nothing. i don't call the super.paint within the button paint method, but do within the screen.

 

here is the paint method for the button and screen below

 

 

Ok the paint method of the button is

 

        protected void paint(Graphics g) {

          // Clear this area to white background, fully opaque.

          g.clear();

          g.setGlobalAlpha(255);

          g.setBackgroundColor(backgroundColour); //SET COLOUR OF BACKGROUND

                  

          // Drawing within our margin.

          int width = getPreferredWidth() - (MARGIN * 2);

          int height = getPreferredHeight() - (MARGIN * 2);

                  

          // Compute paths for the rounded rectangle. The 1st point (0) is on the left

          // side, right where the curve in the top left corner starts. So the top left

          // corner is point 1. These points correspond to our static arrays.

          int[] xPts = {

            0, 0, CURVE_X, width - CURVE_X, width, width,

            width, width, width - CURVE_X, CURVE_X, 0, 0

          };

          int[] yPts = {

            CURVE_Y, 0, 0, 0, 0, CURVE_Y,

            height - CURVE_Y, height, height, height, height, height - CURVE_Y

          };

                  

          // Draw the gradient fill.

          g.drawShadedFilledPath(xPts, yPts, PATH_POINT_TYPES, PATH_GRADIENT, null);

                  

          // Draw a rounded rectangle for the outline.

          // I think that drawRoundRect looks better than drawPathOutline.

          g.setColor(BORDER_COLOR);

          g.drawRoundRect(0, 0, width, height, CURVE_X * 2, CURVE_Y * 2);

                  

          // Place some text in the center.

          

          Font font = Font.getDefault().derive(Font.PLAIN, 9, Ui.UNITS_pt);

          int textWidth = font.getAdvance(someText);

          int textHeight = font.getHeight();

          g.setColor(TEXT_COLOR);

          g.setFont(font);

          g.drawText(someText, 

            (width / 2) - (textWidth / 2) - MARGIN,

            (height / 2) - (textHeight / 2) - MARGIN);

        }

 

 

 

 

and in the construction of the screen i have

 

public FirstScreen() {

            

            super(DEFAULT_CLOSE | DEFAULT_MENU);

            

            VerticalFieldManager vfm  =  new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.FIELD_HCENTER | DrawStyle.HCENTER);

            

            vfm.setBackground(BackgroundFactory.createSolidBackground(0xFFDAB3));

            

            

            

            RoundedRectField playField= new RoundedRectField("Play",0x75B8FF);

            RoundedRectField closeField= new RoundedRectField("Close",0x75B8FF);

            

            playField.setBackground(BackgroundFactory.createSolidBackground(0x75B8FF));

            closeField.setBackground(BackgroundFactory.createSolidBackground(0x75B8FF));

 

            

            

            vfm.add(new LabelField("", USE_ALL_WIDTH));

          vfm.add(playField);

          vfm.add(new LabelField("", USE_ALL_WIDTH));

          vfm.add(closeField);

          vfm.add(new LabelField("", USE_ALL_WIDTH));

          add(vfm);

 

      }

 

 

 

the paint method of the screen just calls super.paint(g);

 

This is pretty much it, everything else is settig object fields and properties.

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

Re: White Box around Rounded Button

The very first statement in your button's paint() method is g.clear() which is what creates that white rectangle (and is exactly what Peter mentioned as the potential problem in his reply). Either precede it with g.setBackgroundColor(0x75B8FF) or remove it.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Regular Contributor
Posts: 82
Registered: ‎10-28-2010
My Device: Not Specified

Re: White Box around Rounded Button

ah,

 

the 3rd line does set the backgroundcolour

 

          g.clear();

          g.setGlobalAlpha(255);

          g.setBackgroundColor(backgroundColour);

 

 

but what have have notice is that the code i pasted for the screen, should have been

 

public FirstScreen() {

            

            super(DEFAULT_CLOSE | DEFAULT_MENU);

            

            VerticalFieldManager vfm  =  new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.FIELD_HCENTER | DrawStyle.HCENTER);

            

            vfm.setBackground(BackgroundFactory.createSolidBackground(0xFFDAB3));

            

            

            

            RoundedRectField playField= new RoundedRectField("Play",0x75B8FF){

                  protected boolean navigationClick(int status, int time){

                        System.out.println("Play Clicked:" + status +":" + time);

                        return true;

                  }

            };

            RoundedRectField closeField= new RoundedRectField("Close",0x75B8FF){

                  protected boolean navigationClick(int status, int time){

                        System.out.println("Close Clicked:" + status +":" + time);

                  

                        return true;

                  }

            };

            

            playField.setBackground(BackgroundFactory.createSolidBackground(0x75B8FF));

            closeField.setBackground(BackgroundFactory.createSolidBackground(0x75B8FF));

 

            

            

            vfm.add(new LabelField("", USE_ALL_WIDTH));

          vfm.add(playField);

          vfm.add(new LabelField("", USE_ALL_WIDTH));

          vfm.add(closeField);

          vfm.add(new LabelField("", USE_ALL_WIDTH));

          add(vfm);

 

      

 

      }

 

 

 

i've noticed that

    RoundedRectField playField= new RoundedRectField("Play",0x75B8FF){

                  protected boolean navigationClick(int status, int time){

                        System.out.println("Play Clicked:" + status +":" + time);

                        return true;

                  }

            };

 doesn't take the aground colour .... inner class not working ?

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

Re: White Box around Rounded Button

 


benabouttown wrote:

ah,

 

the 3rd line does set the backgroundcolour

 

          g.clear();

          g.setGlobalAlpha(255);

          g.setBackgroundColor(backgroundColour);

 


That's too late - you need to set the background color before doing g.clear() (read the docs for it and you'll see why).

 

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