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
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700
Accepted Solution

how to catch field Absolute Y position

HI All,

 

there are a lots of field on screen, it needs to scroll up and down to browser all the field.

 

when user selects one field, i like to pop up some kind of tip near that field.

 

however, the problem is I can not get Field absolute Y position on screen.

 

 

here is my source code:

 

/* * VFMTester.java * * © <your company here>, 2003-2008 * Confidential and proprietary. */ import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.*; import net.rim.device.api.ui.container.MainScreen; import net.rim.device.api.ui.UiApplication; import net.rim.device.api.ui.component.*; import net.rim.device.api.system.*; import net.rim.device.api.servicebook.*; import net.rim.device.api.ui.container.*; /** * */ public class VFMTester extends UiApplication{ public static void main(String args[]){ UiApplication app = new VFMTester(); app.enterEventDispatcher(); } VFMTester() { pushScreen(new AScreen()); } class AScreen extends MainScreen { VerticalFieldManager vfm; public AScreen() { super(); vfm = new VerticalFieldManager(); for(int i=0;i<40;i++){ vfm.add(new ButtonField("Button" + String.valueOf(i))); } this.add(vfm); } public boolean trackwheelClick(int time, int status){ ButtonField f = (ButtonField)vfm.getLeafFieldWithFocus(); final int h = f.getContentTop() - f.getManager().getVerticalScroll(); UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { UiApplication.getUiApplication().pushScreen(new PopupTest(h)); } }); return true; } } class PopupTest extends PopupScreen { int y; PopupTest(int y) { super(new VerticalFieldManager()); this.add(new LabelField("Pop up testing")); this.y = y; } public void sublayout(int width, int height){ super.sublayout(width, height); setPosition(20,y); } protected boolean keyChar(char c, int status,int time) { this.close(); return true; } } }

Only the first screen, works fine, on the second screen, it will pop up lower postion.

 

Thanks in advance.

Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to catch field Absolute Y position

I suspect that you are trying to work in virtual coordinates (looking at this line)

 

final int h = f.getContentTop() - f.getManager().getVerticalScroll();

 

when maybe you need to work in "manager local" coordinates.  You can use any field's getExtent() method to get it's coordinates, so no need to try and pass them.

 

I would basically use Field methods to get the manager local coordinates of the field which has focus, and then offset my popupscreen from there based on proximity to edges perhaps.

 

 

Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: how to catch field Absolute Y position

Hi Berrysoft,

 

Thanks for your suggestion.

 

you are right, what I am looking for is the selected field x,y on screen.

 

but whatever I am trying to use getExtent or field getManger to getFocusXYRect, it still return virtual x,y.

 

Would you mind writing piece of source code?

 

Thanks in advanced.

 

Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: how to catch field Absolute Y position

Hi BerrySoft, I figure it out.

Thanks

 

Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: how to catch field Absolute Y position

Good for you.

Now how about posting the solution, or giving a hint for the people who will be in same trouble as you were?

 

How about closing the thread by marking a given solution (maybe even yours)  Solved ?

 



"Listen carefully, I shall say this only once"
Developer
Jeff_Lu
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: how to catch field Absolute Y position

Here is my source code:

Field.getScreen().getFocusRect(XYRect);

 

New Developer
Oscar
Posts: 18
Registered: ‎07-28-2008
My Device: Not Specified

Re: how to catch field Absolute Y position

 

And this is a good help:

 

private XYPoint getAbsoluteLocation(){
        Manager manager, parentManager = getManager();
        XYPoint XY = new XYPoint(getLeft(),getTop());
        while (parentManager!=null) {
            manager = parentManager;
            XY.translate(manager.getLeft(),manager.getTop());
            parentManager = manager.getManager();
        }
        return XY;
    }