Lucas
Lucas

Reputation: 1279

Custom Manager not rendered properly after being added to a VerticalFieldManager in BlackBerry

I have a VerticalFieldManager that renders a white round rectangle.

This is the code:

 VerticalFieldManager _vfmBackground = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | 
                Manager.NO_VERTICAL_SCROLLBAR | Manager.USE_ALL_WIDTH){
             public void paint(Graphics graphics)
                {
                    graphics.clear();
                    graphics.setColor(Color.WHITE);
                    graphics.fillRoundRect(10, 10,460, 400, 25,25 );
                    super.paint(graphics);
                }

              protected void sublayout(int maxWidth, int maxHeight)
                {
                    int displayWidth = (Display.getWidth());
                    int displayHeight = (Display.getHeight());

                    super.sublayout( displayWidth, displayHeight);
                    setExtent( displayWidth, displayHeight);
                }

        };

Then I create a custom Manager class named BaseHeaderBlueScreen that renders a blue rectangle:

public void paint(Graphics graphics)
    {
     graphics.clear();
     graphics.setColor(610212);
     graphics.fillRect(20, 0, Display.getWidth(), Display.getHeight());
     super.paint(graphics);
    }

    protected void sublayout(int maxWidth, int maxHeight)
    {
        int displayWidth = (Display.getWidth()-40);
        int displayHeight = ((Display.getHeight()/2))-90;

        super.setExtent( displayWidth, displayHeight);
    }   

Finally, I add that custom manager to the VerticalFieldManager with the white rounded rectangle:

BaseHeaderBlueScreen _vhbs = new BaseHeaderBlueScreen(textTop, textBottom, 0);
        _vhbs.setPadding(20,30,0,0);
        _vfmBackground.add(_vhbs);

This is how the blue rectangle should be displayed within the white rectangle.

enter image description here

But this is how the blue rectangle is currently being displayed (please note the gray space of its left side):

enter image description here

How should I do to render the blue rectangle exactly as desired (without the left gray border)?

Upvotes: 1

Views: 111

Answers (1)

Nate
Nate

Reputation: 31045

I think you're just unnecessarily making a call to Graphics.clear(). clear() is meant to fill in the graphics area with whatever color is currently set as the background color. Normally, you would use clear() like this:

public void paint(Graphics g) {
    g.setBackgroundColor(Color.GRAY);
    // calling clear makes the background gray
    g.clear();

    // now draw some text
    g.setColor(Color.WHITE);
    g.drawText("hello", 20, 40);
}

From the API docs for clear():

Clears the entire graphics area to the current background color. Note that global alpha is not applied in this case.

But, you're calling clear() before you make any other calls.

So, just remove the two calls to clear() (although the one that's causing this particular problem is the call in BaseHeaderBlueScreen.paint()).

Upvotes: 1

Related Questions