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
vercity
Posts: 27
Registered: ‎08-04-2010
My Device: Not Specified
Accepted Solution

How can i get the position of a field in a manager?

Hi all

 

I just wanna to know that how can i get a field's position in a manager(Vertical or Flow)?

 

If i get the x,y position, than i can make a popup screen depends on this position....

 

 Can anyone help me to solve this?

 

 Many thanks.

Please use plain text.
Developer
swati-srivastava
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: How can i get the position of a field in a manager?

may be u can try this:

 

 

int index = getFieldWithFocusIndex();

Field f = getField(index);

Manager m = (Manager)f;

//above 3 steps are done if multiple managers(containing fields) are added to screen and u want to get index of manager

int index1 = m.getFieldWithFocusIndex()();
//above line is written to get index of focused field inside that manager

Field f1 = m.getField(index1);
//above line is written to get field on which current focus exists


//below mentioned are 4 methods that u can use to calculate your values
f1.getLeft();
f1.getTop();
f1.getHeight();
f1.getWidth();

 

 

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

Re: How can i get the position of a field in a manager?

welcome to the forums.

 

I use getFocusRect to retrieve the XYRect of the focused field. you can get the coordinates from there.

----------------------------------------------------------
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.
Developer
swati-srivastava
Posts: 282
Registered: ‎02-25-2010
My Device: curve,bold,storm
My Carrier: Verizon,AT&T

Re: How can i get the position of a field in a manager?

hey Simon's idea is cool and has less code tooooooo

Please use plain text.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: How can i get the position of a field in a manager?

[ Edited ]

Hi Simon,

please help me on this issue.

But when i use this it will hides my field. here in getFocusRext am passing my fields Extent values. but i get the x and y positions but i the field was not drawing. can u please help me on this issue.

 

in my code i am using this

 

getScreen().getFocusRect(this.getExtent());

 

is this correct to set the Focus Rect. a give me  a sample to get this.

 

 

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

Re: How can i get the position of a field in a manager?

create a new extent object and pass it to the method, it will fill its values.
to draw a tooltip we modify the coordinates a bit to avoid it overlapping with the field and paint it directly on the screen.

you can also use the search about "tooltip", there were some threads about it i recall.
----------------------------------------------------------
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.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: How can i get the position of a field in a manager?

Hi Simon,

 

Thanks for the replay.

 

i tried getScreen().getFocusRect(new XYRect());  

 

 

and then how can i get the x and y positions

 

 

can i use this.getExtent().x and this.getExtent().y to get the x and y corditions is it right.

 

Where can i set this object at the time of initicalization. right now i am initializing this at the time of onFocus(). it won't return any values can u please help me.

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

Re: How can i get the position of a field in a manager?

you have to reference the xyRect, like
XYRect xyRect = new XYRect();
getFocusRect(xyRect);
xyRect.x now contains the x coordinate.
----------------------------------------------------------
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.
Super Contributor
bh1r1th
Posts: 273
Registered: ‎11-23-2010
My Device: 9800 torch
My Carrier: Software Programmer

Re: How can i get the position of a field in a manager?

Thank you simon.

 

it's working fine.

Please use plain text.