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
Highlighted
Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000
Accepted Solution

how to set coordinates, width and height for a Manager?

hi, i stuck with a manager. is there any possibility for me to define where my Manager should starts? cause i do not want it to start from (0,0)..
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to set coordinates, width and height for a Manager?

Call setPosition(x,y) from within the sublayout method.
Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to set coordinates, width and height for a Manager?

that is useles.. i've tried setPosition and also setChildPosition. and i set coordinates (30,30)-so my manager should 'start' at (30,30). then i add a LabelField with a text and text always appears in left top corner.. why is that? how can i set manager's coordinates so that, after i add a field with a text, the text would also started from (30,30) or different, definied by me coordinates?
Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: how to set coordinates, width and height for a Manager?

if you just want to move the manager down the screen, override the layout function and add 30 to the y position of your fields, or override the paint method and start painting your manager 30 pixels down the screen. If you want to use custom coordinates, you will need to override the screen and manager classes and add a vriable to track the x,y location where you want to draw the field. You can do this two ways in my opinion:

 

1. You can use the x,y values within the paint method of the field and start painting at that location

2. You can use the push/pop context methods of the graphics class with the x,y values in the screen and in the manager assume you always start at 0 

Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to set coordinates, width and height for a Manager?

sublayout - i've tried to ovverwrite it and use there setPosition(x,y) method and also i set width and height:

 

super.sublayout(_width, _height);

setExtent(_width, _height);

 

but it doesn't work cause when i add a TextField to the manager, the text appears in the left top corner, not in the (x,y) coordinates.

 

paint - i've tried  

super.invalidate(x, y, width, height)

 

but also when i added a TextField, text appeared in left top corner not in (x,y)

 

rest of Your post is not understandable for me..

Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to set coordinates, width and height for a Manager?

is there any simply way to set start coordinates, width and height for a Manager?

something like:

 

Manager.setCoordinates(x,y);

setWitdth(wwidth);

setHeight(height);

 

so that after i done this,everything on this manager will 'happen' in the area i defined? if i would like to add a text it would appear in (x,y) coordinates but not further than width and height?

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to set coordinates, width and height for a Manager?

You can override sublayout of a manager to fix height and width.

And you can try with setPadding() for startCoordinates.

 

Have a look at the following MainScreen. You will get some idea.

 

TestScreen() { super(NO_VERTICAL_SCROLL); final int topGap = 30; final int leftGap = 30; VerticalFieldManager verticalManager = new VerticalFieldManager (Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) {

//color of the manager

public void paint(Graphics graphics) { graphics.setBackgroundColor(0x00000000); graphics.clear(); super.paint(graphics); }

  //height and width of the manager

protected void sublayout( int maxWidth, int maxHeight ) { int displayWidth = Display.getWidth() - leftGap; int displayHeight = Display.getHeight() - topGap; super.sublayout( displayWidth, displayHeight); setExtent( displayWidth, displayHeight); } };

  //setting start coordinates

verticalManager.setPadding(leftGap, 0, 0, topGap); verticalManager.add(new LabelField("TestLabel")); verticalManager.add(new ButtonField("Button")); this.add(verticalManager); }

 

Regards

Bikas

 

 

Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to set coordinates, width and height for a Manager?

actually, i think that my head will explode soon. i do not understand why it is so difficult ;/ do You know how can i divide a screen into 4? ok, i'm trying to use this *** Manager, but the best i get is two separate Manager-one under one.. and i want to have something like:

 

 A | B

_____

C  |  D

Developer
Posts: 745
Registered: ‎01-04-2009
My Device: 8300, 8800, 8700f, 9000

Re: how to set coordinates, width and height for a Manager?

here is my class:

 

public class Monitor extends FlowFieldManager{ private FlowFieldManager _monitor; private int _x; private int _y; private int _width; private int _height; public Monitor(int _cx, int _cy, int _w, int _h){ super(Manager.HORIZONTAL_SCROLLBAR); _x = _cx; _y = _cy; _width = _w; _height = _h; _monitor = new FlowFieldManager(Manager.HORIZONTAL_SCROLL); add(_monitor); } public void paint(Graphics _g){ super.paint(_g); _g.setColor(Color.BLACK); _g.drawRect(_x, _y, _width, _height); }//end of paint() method public void sublayout(int _w, int _h){ setPosition(_x,_y); super.sublayout(_width, _height); setExtent(_width, _height); }//end of sublayout }//end of Monitor class

 

 

i've tried this also for VerticalFieldManager and HorizontalFieldManager-always the same result. now, i would like to create two Monitor-objects, one next to another. i'm creating them in a MainScreen class:

 

Monitor _monitor1 = new Monitor(0, 0, 50, 50);

add(_monitor1);

Monitor _monitor2 =
new Monitor(60, 0, 170, 100);

add(_monitor2);

 

what i expect is two objects-one 'starts' at (0,0) and has width = 50 and height = 50. second one-starts at (60,0) with a width = 170 and height = 100. unfortunatelly that is not true. the second object recognizes it's y-0 coordinate as the one in which the first object ends. so actually, my seconds objects 'starts' at 0+50... and that is the reason i get them one under another all the time. if i'll try to set it's y-0 coordinate to '-50', then simply part of the second object won't be visibile..

 

can anyone please help me solve this problem? i must got four 'monitors' like that:

 

A | B

--------

C | D

 

how can i make it that the would appear one next to another?

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: how to set coordinates, width and height for a Manager?

About your first problem .. placing 2 monitor.

----------------------------------------------------------------

First: make a manager with your required width and heigh and color

Second: set them in the main screen accordingly. use padding or margin if required.

 

Have a look at the following screen. You can try something like this:

 

import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.system.*; class TestScreen extends MainScreen { TestScreen() { super(NO_VERTICAL_SCROLL); VerticalFieldManager monitor1 = getCustomVerticalManager(0x0000FF00, 50, 50); this.add(monitor1); VerticalFieldManager monitor2 = getCustomVerticalManager(0x0000FFFF, 170, 100); monitor1.setPadding(10, 0, 0, 0); this.add(monitor1); } public VerticalFieldManager getCustomVerticalManager(final int color, final int width, final int height) { VerticalFieldManager verticalManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR) { public void paint(Graphics graphics) { graphics.setBackgroundColor(color); graphics.clear(); super.paint(graphics); } protected void sublayout( int maxWidth, int maxHeight ) { int displayWidth = width; int displayHeight = height; super.sublayout( displayWidth, displayHeight); setExtent( displayWidth, displayHeight); } }; return verticalManager; } }

 

Regards

Bikas