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
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300
My Carrier: Personal
Accepted Solution

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.

 

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

 

 

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

 

Thanks in advance!

Please use plain text.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

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

either overwrite sublayout or not.
calling super.sublayout followed by setExtent makes the system all confused.

after using the color you should reset it on the graphics object (store getColor, use it with setColor afterwards).

you can also use paintBackground, which is not called as often as 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.
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300
My Carrier: Personal

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

thanks Simon, but I'm confused... where should I do what you recommended?
Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

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

This looks at first glance like a bug. 

 

But there are some off things going on in your Managers.  So I recommend that you review the following:

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

I am not the best person on the forum for these issues, but until he comes round, I will try to help.  First thing is this code is confused:

 

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);
}

};

The objective of a sublayout is to layout the contained Fields and then define how much space it needs.  So the last thing in sublayout is typically a setExtent.  Now you coded this:

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

So you are asking the super to layout the Fields and then dp its setExtent, then ignoring it and setting your own.  I think this is contributing to the problem.

 

Moreover, when sublayout is called the width and height passed in are the maximum that you can use.  You should not use Display.getheight() and Display.getWidth() without making sure that the Manager can actually use this amount.  In this case I don't think it can.  So you shoud code:

int displayWidth = Math.max(Display.getWidth(),maxWidth);
int displayHeight = Math.max(Display.getHeight(),maxHeight);

 

Anyway the idea behind this Manager is, I believe to fill the whole screen, and then paint a rounded corner background.  To do this I think you just need this:

 

VerticalFieldManager _vfmBackground = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL |

Manager.NO_HORIZONTAL_SCROLL | Manager.USE_ALL_HEIGHT | 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);
}

};

 

I think similar comments apply to the second Manager.  One question - What does this class extend?. 

 

Anyway, fix up your sublayouts as suggested and tell us if the grey still remains.   

 

And before we move on,

1) I would strongly caution against using hardcoded pixel positions or sizes in any code you have. 

2) have you looked a the Background class as a way of achieving this too. 

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,598
Registered: ‎07-14-2008
My Device: Not Specified

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

Simon makes a good point (as usual).

 

{
graphics.clear();
graphics.setColor(Color.WHITE);
graphics.fillRoundRect(10, 10,460, 400, 25,25 );
super.paint(graphics);
}

 

should be:

 

{
graphics.clear();

int currcol = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fillRoundRect(10, 10,460, 400, 25,25 );

graphics.setColor(currcol);
super.paint(graphics);
}

Please use plain text.
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300
My Carrier: Personal

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

Thanks for the answer Simon. 

This is how the paint methods are overrided now:

-Blue rectangle:

public void paint(Graphics graphics)
 {
graphics.clear();

int currcol = graphics.getColor();
graphics.setColor(610212);
graphics.fillRect(x, 0,Display.getWidth(), Display.getHeight());

graphics.setColor(currcol);
super.paint(graphics);

}

 

White backgournd:

public void paint(Graphics graphics)
 {
graphics.clear();

int currcol = graphics.getColor();
graphics.setColor(Color.WHITE);
graphics.fillRoundRect(10, 10,460, 400, 25,25 );

graphics.setColor(currcol);
super.paint(graphics);
}

 

But the problem persists. Regarding the gray background of the screen, it is defined on a superclass and this is how is made:

VerticalFieldManager _vfmBackground = new VerticalFieldManager(
Manager.VERTICAL_SCROLL |
Manager.VERTICAL_SCROLLBAR ){
public void paint(Graphics graphics)
{
graphics.setBackgroundColor(15724527);
graphics.clear();
super.paint(graphics);
}

 

I did your suggestion but the problem persists :smileysad:

protected void sublayout( int maxWidth, int maxHeight )
{
int width = Display.getWidth();
int height = Display.getHeight();
super.sublayout( width, height);
setExtent( width, height);
}
};

Please use plain text.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

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

you still call setExtent after super.sublayout.
you also use Display.getWidth in paint, but you should use the width available, so just getHeight, as the field is already layouted when it is painted.
----------------------------------------------------------
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.
Contributor
nordavinder
Posts: 23
Registered: ‎12-02-2012
My Device: BlackBerry 8300
My Carrier: Personal

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

Hi Thanks, I just removed the clear() calls from both paint() methods and now it works!

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

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

[ Edited ]

Even though this thread is solved, I decided to quickly summarize what I think about all this:

 

1) The advice to use paintBackground instead of paint (and, of course, skip calling super.paint there) is a very sound one - it will yield a better performance and is much clearer logically;

2) Saving and restoring the color before and after setColor/fillRoundRect is an absolute necessity - you are going to create a lot of graphical artifacts otherwise;

3) your sublayout override is wrong - if you want the manager to occupy the whole screen, do something like this:

protected void sublayout(int maxWidth, int maxHeight) {
  super.sublayout(Math.min(maxWidth, Display.getWidth()), Math.min(maxHeight, Display.getHeight()));
}

 and create your Manager with USE_ALL_WIDTH | USE_ALL_HEIGHT in addition to the rest of the style bits (such as NO_VERTICAL_SCROLL etc.).

4) I'm not sure about the NO_VERTICAL_SCROLL part here - good if you really don't want any scrolling, of course, but your MainScreen (if you are using that) is scrolling by default, somewhat defeating the purpose. Disregard this remark if you are using FullScreen or create your MainScreen with NO_VERTICAL_SCROLL as well;

5) graphics.clear() uses your graphics' background color which you never set. If you want a specific result, specify that color first (again, saving it before and restoring it afterwards). The results of this call are never transparent (unless you specify a color with alpha as your background color - that's what the Javadoc is claiming, though I don't know how to achieve it in practice). Anyway, you really don't want that call on your inner Manager (it's OK on _vfmBackground, though) if you are to achieve the result you need.

 

If you need more specifics, don't hesitate to ask here or send me a private message. I'm not as active on these forums as I used to be, but can still explain a lot about Fields, Managers and graphics. :smileyhappy:

----------------------------------------------------------
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.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

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


arkadyz wrote:

If you need more specifics, don't hesitate to ask here or send me a private message. I'm not as active on these forums as I used to be, but can still explain a lot about Fields, Managers and graphics. :smileyhappy:


Oh yes.

----------------------------------------------------------
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.