AbsoluteFieldManager: setPosChild vs setPositionChild

What are the differences between the method of setPosChild of AbsoluteFieldManager and its hereditary setPositionChild, and what should be used?

Welcome on the support forums.

setPositionChild is final and cannot be overwritten, for this reason, the method is named setPosChild.

setPosChild should only be used.

Tags: BlackBerry Developers

Similar Questions

  • Horizontal Scrolling in AbsoluteFieldManager

    Hello

    I am trying to add several labels to an AbsoluteFieldManager as follows:

            final AbsoluteFieldManager man = new AbsoluteFieldManager();
    
            man.add(new LabelField("1", Field.FOCUSABLE), 20, 0);
            man.add(new LabelField("2", Field.FOCUSABLE), 30, 100);
            man.add(new LabelField("3", Field.FOCUSABLE), 0, 200);
            man.add(new LabelField("4", Field.FOCUSABLE), 0, 220);
            man.add(new LabelField("5", Field.FOCUSABLE), 150, 240);
            man.add(new LabelField("6", Field.FOCUSABLE), 300, 260);
            man.add(new LabelField("7", Field.FOCUSABLE), 300, 280);
            man.add(new LabelField("8", Field.FOCUSABLE), 300, 300);
            man.add(new LabelField("9", Field.FOCUSABLE), 300, 320);
            man.add(new LabelField("10", Field.FOCUSABLE), 350, 320);
            man.add(new LabelField("11", Field.FOCUSABLE), 400, 320);
            man.add(new LabelField("12", Field.FOCUSABLE), 450, 320);
            man.add(new LabelField("13", Field.FOCUSABLE), 500, 320);
            man.add(new LabelField("14", Field.FOCUSABLE), 550, 320);
            man.add(new LabelField("15", Field.FOCUSABLE), 600, 320);
            this.add(man);
    

    When I move on the trackpad, the next label Gets the focus. This works well in the direction y. All labels with Label '12' are visible. When I try to get the focus to the next label, '12' Label loses focus. '13' label now has the development in-house, but it is not visible and no scrolling happens. Ditto for the "14" and "15". It is easy to notice, the focus moves to the 14 and 15, because it takes a lot of movement on the trackpad to return to 12. But why the AbsoluteFieldManager scrolls at 13, 14 and 15 to make them visible?

    I also tried to add the AbsoluteFieldManager to a HorizontalScreenManager that has vertical and horizontal scrolling. Then, it is even possible to scroll, but not yet all of the labels are visible.

    Is that what I can do to make it possible that the AbsoluteFieldManager scrolls auotmatically once a field outside of the visible area Gets the focus?

    Thank you

    Hello

    Finally, I made my own AbsoluteFieldManager. It works really well. You can position your fields anywhere and just highlight the field you want. I also substitute nextFocus() which now moves according to the movement of pad/trackball. I think it is fairly intuitive and not according to the order of the fields. You can also use it on Blackberry OS prior to 5, where AbsoluteFieldManager is not supported.

    This thread helped me a lot:

    http://supportforums.BlackBerry.com/T5/Java-development/AbsoluteFieldManager-on-OS-prior-to-5-0/TD-p...

    Here is the code, feel free to use or improve.

    import java.util.Vector;
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.XYPoint;
    
    public class ImageMenuFieldManager extends Manager
    {
    
        protected Vector _coordinates;
    
        public ImageMenuFieldManager()
        {
            super(Manager.VERTICAL_SCROLL | Manager.HORIZONTAL_SCROLL);
            _coordinates = new Vector();
    
        }
    
           public int getPreferredWidth()
          {
                return Integer.MAX_VALUE >> 1;
           }
    
           public int getPreferredHeight()
            {
               return Integer.MAX_VALUE >> 1;
           }
    
        protected void sublayout(final int maxWidth, final int maxHeight)
        {
            int totalWidth = 0;
            int totalHeight = 0;
            final int noOfFields = getFieldCount();
            final int maxSize = Integer.MAX_VALUE >> 1;
    
            for (int i = 0; i < noOfFields; ++i)
            {
                final XYPoint fieldPos = (XYPoint) _coordinates.elementAt(i);
                final Field field = getField(i);
                layoutChild(field, maxSize - fieldPos.x, maxSize - fieldPos.y);
                setPositionChild(field, fieldPos.x, fieldPos.y);
                totalWidth = Math.max(totalWidth, field.getExtent().X2());
                totalHeight = Math.max(totalHeight, field.getExtent().Y2());
            }
            setExtent(Math.min(maxWidth, totalWidth), Math.min(maxHeight, totalHeight));
            setVirtualExtent(totalWidth, totalHeight);
        }
    
        protected int nextFocus(final int direction, final int axis)
        {
    
            final int focusFieldIndex = this.getFieldWithFocusIndex();
    
            final int size = _coordinates.size();
            final XYPoint position = (XYPoint) _coordinates.elementAt(focusFieldIndex);
            int shortestAbsoluteDistance = 0;
            int nearestIndex = focusFieldIndex;
            for (int i = 0; i < size; i++)
            {
                //skip focus field
                if (i != focusFieldIndex)
                {
    
                    final XYPoint p = (XYPoint) _coordinates.elementAt(i);
                    final int xDistance = p.x - position.x;
                    final int yDistance = p.y - position.y;
                    final int absoluteDistance = (xDistance * xDistance) + (yDistance * yDistance);
    
                    //point p is in direction right
                    if (direction > 0 && xDistance > 0 && axis == Manager.AXIS_HORIZONTAL)
                    {
                        if (absoluteDistance < shortestAbsoluteDistance || shortestAbsoluteDistance == 0)
                        {
                            shortestAbsoluteDistance = absoluteDistance;
                            nearestIndex = i;
                        }
                    }
                    //point p is in direction left
                    if (direction < 0 && xDistance < 0 && axis == Manager.AXIS_HORIZONTAL)
                    {
                        if (absoluteDistance < shortestAbsoluteDistance || shortestAbsoluteDistance == 0)
                        {
                            shortestAbsoluteDistance = absoluteDistance;
                            nearestIndex = i;
                        }
                    }
    
                    //point p is in direction down
                    if (direction > 0 && yDistance > 0 && axis == Manager.AXIS_VERTICAL)
                    {
                        if (absoluteDistance < shortestAbsoluteDistance || shortestAbsoluteDistance == 0)
                        {
                            shortestAbsoluteDistance = absoluteDistance;
                            nearestIndex = i;
                        }
                    }
    
                    //point p is in direction up
                    if (direction < 0 && yDistance < 0 && axis == Manager.AXIS_VERTICAL)
                    {
                        if (absoluteDistance < shortestAbsoluteDistance || shortestAbsoluteDistance == 0)
                        {
                            shortestAbsoluteDistance = absoluteDistance;
                            nearestIndex = i;
                        }
                    }
    
                }
            }
    
            return nearestIndex;
    
        }
    
        public void add(final Field field)
        {
            throw new IllegalArgumentException("You need to provide x and y coordinates to add a field. Use add (Field field, int x, int y) instead");
        }
    
        public void add(final Field field, final int x, final int y)
        {
            super.add(field);
            this._coordinates.addElement(new XYPoint(x, y));
            updateLayout();
        }
    
    }
    
  • How setpositionchild settings?

    When I use - setPositionChild (field, x, y);

    x offset from the left of the field of his Manager.

    What is meant by ' shift to the left of the field of his Manager.? I'd like to find out what the current offset

    Currently I'm using setPositionChild (field, 0,0); But the field is pushed to the right by 32 pixels.

    Thank you

    0.0 means that the field is positioned in the upper left corner of the Manager.
    If it is also the left upper corner of the screen depends on the position of the manager etc.

  • In AbsoluteFieldManager Z-order

    Is there an easy way to adjust the order of fields on an AbsoluteFieldManager? It seems that the withdrawal and time fields will work, but it would be nice if there was an easier way to do...

    Just guessing here, but I suspect the paint Manager method can control the order of the paint, so you might be able to override this somehow and paint the children directly.  But I'm just guessing and I have no idea how do.  So not much help really...  Sorry

  • AbsoluteFieldManager inside another Manager

    Hello. I'm trying to place my AbsoluteFieldManager inside another Manager. Basically, I want my absManager at the bottom of the screen (like setStatus). I couldn't find a way to achieve this properly so I created a HorizontalFieldManager, setStatus (hManager) and now I wanted to add the absManager to hManager but it gives me an error saying that it is already apparent.

    What I'm trying to do, is have a bar of tabs at the bottom of the screen, what I did with success in using hManager. The thing is that I want to place my tabs where I want.

    Any help would be greatly appreciated.

    Thank you.

    I just setPadding instead of setMargin and it works. Background image of the horizontalFieldManager seems to stop at the margin, so the margin of a HorizontalFieldManager with a background image the assignment will result in white space.

    Thanks for the help.

  • Absolutefieldmanager with vertical scrolling

    How can it be done?

    I give a certain field e.g. y 700 off the page... How can I get there through scrolling? and can even appear on the page?

    I worked on it. I made a grid and in absolutefieldmanager.
    So I had in a grid of 10, 10 absolutefeidlmanagers.

    What I was doing, make one an absolutefeildmanager... and fill the grid in it.

  • Put an AbsoluteFieldManager under the banner of screens

    I'm trying to use setBanner() to fix my AbsoluteFieldManager header to the top of the applications without making it disappear when I scroll down. The problem I have is that the header displays fine, but when I try to add anything to the screen it never gets displayed, either a field or a Manager with several fields.

    This problem only occurs when I use an AbsoluteFieldManager. It works very well with other types of managers. No idea how to fix this?

    I'm sure that AbsoluteFieldManager always eat the whole width and height than him (behave as if USE_ALL_WIDTH |) USE_ALL_HEIGHT has been specified).  If you think about its features, you'll understand why.

    Or substitute his sublayout to limit the height or stop using it at all. Here's one possibility:

    protected void sublayout(int maxWidth, int maxHeight) {
      super.sublayout(maxWidth, Math.min(maxHeight, Display.getHeight() / 5));
    }
    
  • Buttons disappear when using setPositionChild

    I want to align multiple columns of buttons where each column has three buttons.  When I add up to four columns, everything looks great, I added more than four columns, the first columns begin to disappear.

    Is there a limit on the number of fields of button in a VerticalFieldManager, or something else underway?

    Thanks for the help!

    JDE 4.7

    protected void sublayout (int width, int height)
    {
    Which int = 0;
    int YPosition = 0;
    int Count = 0;
    int iNumFields = getFieldCount();

    for (int i = 0; i)
    {
    Field = this.getField (i);
    layoutChild (field, 48, 48);
    setPositionChild (field, which, YPosition);
    PositionY = PositionY + 48;
               
    Count = Count + 1;
    If (Count is 3)
    {
    Count = 0;
    PositionY = 0;
    Which = which + 48;
    }
    }
    setExtent (Display.getWidth (), 144);
    }

    I forgot to close this topic.

    I'm a * beep *.  I had a vertical field Manager and did not notice for some reason any.

    Once I went to Manager instead of VerticalFieldManager.  It worked?

    I'm sorry to bother everyone.

  • Add the function seems not working in AbsoluteFieldManager

    It seems strange that when I try to delete a field (for example, playButton) and replace it with another (e.g., pauseButton), it works the first time, when I try to replace the pauseButton with the playButton, it let me just a hole, where is bad?

       public void playToPause() {       delete(playButton);       add(pauseButton);     pauseButton.setFocus();   }
    
       public void pauseToPlay() {       delete(pauseButton);      add(playButton);      playButton.setFocus();    }
    

    When I call the function playToPause() that it works, but after that when I call the function pauseToPlay() , pauseButton disappears, but the playButton does not appear. I also tried the "replace (oldField, newField)", it does not work as well. What should I do?

    Oh, I finally noticed that I have replace the "sublayout" of another class in a bad way. Nothing wrong with the class ControlButton.

  • HorizontalFieldManager added to the bottom of the screen (to show the user a cost)

    Hello, I am trying to pin a HorizontalFieldManager towards the bottom of the screen and have a VerticalFieldManager scroll over it. I searched and found that I can do this through the substitution of the method sublayout of my screen. Note: I know I could use the setStatus() of a class display method, but I need of this screen to be just a screen and not a screen. Here is a picture of what I'm trying to accomplish:

    So the blue VerticalFieldManager should be scrollable to allow the user to select toppings for their food, and the Red HorizontalFieldManager should be set so that the user can always see their total (and continue to the next screen to complete their order)

    Here is the code that I have to do:

    protected void sublayout(int width, int height) {
            layoutChild(redManager, width, height);
            setPositionChild(redManager, 0, height);
            layoutChild(blueManager, width, height - redManager.getHeight());
            setPositionChild(blueManager, 0, 0);
            setExtent(width, height);
            }
    

    However, I get an error: IllegalArgumentException: field is not a child of this Manager. How I add the fields to the screen is as follows:

    public MyScreen extends Screen {
            ...
            public MyScreen() {
                this.add(blueManager);
                this.add(redManager);
            }
    }
    }
    

    Also, using an AbsoluteFieldManager has also been proven not

    Hello

    post previous sorry was by mistake... try this.

    VerticalFieldManager ScrollingVFM = new VerticalFieldManager() {}
    protected void sublayout (int width, int height) {}

    Super.sublayout (width, height);
    setExtent (Display.getwidth (), Display.getHeight () - bottomHFMHeight);
    }
    }

    Add this to the screen and add your background hfm to screen

    Kind regards

    pp

  • ListField and table LayoutManager

    Hello.

    I think that maybe that's my problem.

    I make use of this TableLayoutmanager (that I found on this site):

    public class TableLayoutManager extends Manager{ public TableLayoutManager(){ super(0); }     public void drawRow(Graphics g, int x, int y, int width, int height){ // Arrange the cell fields within this row manager. layout(width, height); // Place this row manager within its enclosing list. setPosition(x, y); // Apply a translating/clipping transformation to the graphics // context so that this row paints in the right area. g.pushRegion(getExtent()); // Paint this manager's controlled fields. subpaint(g); g.setColor(0x00CACACA); g.drawLine(0, 0, getPreferredWidth(), 0); // Restore the graphics context. g.popContext(); } protected void sublayout(int width, int height) { // TODO Auto-generated method stub int preferredWidth = getPreferredWidth(); int preferredHeight = getPreferredHeight(); Field field = getField(0); layoutChild(field, preferredWidth - 110, preferredHeight); setPositionChild(field, 35, 12); field = getField(1); layoutChild(field, 75, preferredHeight); setPositionChild(field, preferredWidth-75, 11); setExtent(preferredWidth, preferredHeight); } public int getPreferredWidth() { return Graphics.getScreenWidth(); } // The preferred height of a row is the "row height" as defined in the // enclosing list. public int getPreferredHeight() { return getContentHeight(); } }
    

    for this ListField:

    public class MenuListField extends ListField implements ListFieldCallback { /* * This code created based on rtm4bb HomeMenuListField.java */ private Font font; TableLayoutManager[] rows; public MenuListField(){ // this number should be the same with rows = new TableRowManager[7] // or list item in item field wont show super(9); setEmptyString("sorry, No Menu", DrawStyle.HCENTER); setCallback(this); // this row height to show the height setRowHeight(36); font = Font.getDefault(); rows = new TableLayoutManager[9]; // create a table row manager rows[0] = new TableLayoutManager(); // set the menu item name rows[0].add(new RichTextField("Computer Literacy", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[0].add(new LabelField("All our Computer Literacy Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[0].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[1] = new TableLayoutManager(); // set the menu item name rows[1].add(new RichTextField("Office Assistant", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[1].add(new LabelField("Secretarial Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[1].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[2] = new TableLayoutManager(); // set the menu item name rows[2].add(new RichTextField("Pastel", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[2].add(new LabelField("Pastel Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[2].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[3] = new TableLayoutManager(); // set the menu item name rows[3].add(new RichTextField("Technical", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[3].add(new LabelField("Technical Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[3].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[4] = new TableLayoutManager(); // set the menu item name rows[4].add(new RichTextField("Graphic Design", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[4].add(new LabelField("Graphic Design Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[4].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[5] = new TableLayoutManager(); // set the menu item name rows[5].add(new RichTextField("IT", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[5].add(new LabelField("Our IT Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[5].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[6] = new TableLayoutManager(); // set the menu item name rows[6].add(new RichTextField("Web Design", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[6].add(new LabelField("Web Design Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[6].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[7] = new TableLayoutManager(); // set the menu item name rows[7].add(new RichTextField("Programming", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[7].add(new LabelField("Our Programming Options", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[7].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[8] = new TableLayoutManager(); // set the menu item name rows[8].add(new RichTextField("Business Admin", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[8].add(new LabelField("Business Oriented Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[8].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); // create a table row manager rows[9] = new TableLayoutManager(); // set the menu item name rows[9].add(new RichTextField("Two Year", DrawStyle.ELLIPSIS)); // set the number of list items if there are any rows[9].add(new LabelField("Two Year Courses", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); rows[9].add(new LabelField("For All Prices and Course Content, Click Here!", DrawStyle.ELLIPSIS | Field.USE_ALL_WIDTH | DrawStyle.RIGHT)); } public void drawListRow(ListField listField, Graphics graphics, int index, int y, int width) { // TODO Auto-generated method stub MenuListField list = (MenuListField) listField; TableLayoutManager rowManager = list.rows[index]; rowManager.drawRow(graphics, 0, y, width, list.getRowHeight()); } public Object get(ListField listField, int index) { // TODO Auto-generated method stub return null; } public int getPreferredWidth(ListField listField) { // TODO Auto-generated method stub return Graphics.getScreenWidth(); } public int indexOfList(ListField listField, String prefix, int start) { // TODO Auto-generated method stub return -1; } protected boolean trackwheelClick(int status, int time) { int index = getSelectedIndex(); // Dialog.inform("Clicked " + Integer.toString(index)); /*if( index == 0 ) { new MenuCategoryController(); } */ switch(index) { case 0: UiApplication.getUiApplication().pushScreen(new ComputerLiteracyScreen()); break; case 1: UiApplication.getUiApplication().pushScreen(new OfficeAssistantScreen()); break; case 2: UiApplication.getUiApplication().pushScreen(new PastelScreen()); break; case 3: UiApplication.getUiApplication().pushScreen(new TechnicalScreen()); break; case 4: UiApplication.getUiApplication().pushScreen(new GraphicDesignScreen()); break; case 5: UiApplication.getUiApplication().pushScreen(new ITScreen()); break; case 6: UiApplication.getUiApplication().pushScreen(new WebDesignScreen()); break; case 7: UiApplication.getUiApplication().pushScreen(new ProgrammingScreen()); break; case 8: UiApplication.getUiApplication().pushScreen(new BusinessAdminScreen()); break; case 9:      UiApplication.getUiApplication().pushScreen(new TwoYearScreen());   break; } return true; } }
    

    And I call it like:

     MenuListField mylist = new MenuListField();
    

    Now my app keeps throwing errors IndexOutOfBounds.

    I've implemented the table layout manager properly?

    Hannes

    In your situation, I think that most of the BlackBerry users expect to see a drill down, where they see a list of courses in a ListField, then click on the course to see more detail for this course in a different window.

  • Virtual keyboard hides part of the change to the field

    Hello

    I have a labelfield, field change and a button that are centered aligned vertically. The three fields, I added in a Verticalfield Manager which is then added to a horizontal region Manager. And finally the HFM is added to an another value for money. Now in the 9800 device or curve 9380, I noticed that when I touch the edit field, virtual keyboard is coming. And he hides the field partially change.

    I want to move things to the top when the virtual keyboard appeared. How can I do. My code is here:

           HorizontalFieldManager hfm = new HorizontalFieldManager();
            VerticalFieldManager vfmComponent = new VerticalFieldManager(USE_ALL_WIDTH);
            vfmComponent.add(lfServerUrl);
            vfmComponent.add(mEfURL);
            vfmComponent.add(mBtnSave);
            hfm.add(vfmComponent);
            int topEmptySpace = (Display.getHeight() - (Bitmap.getBitmapResource(mStrTopBar).getHeight() + hfm.getPreferredHeight() + 25)) / 2;
            hfm.setMargin(topEmptySpace, 0, 0, 0);
            VerticalFieldManager vfmMain = new VerticalFieldManager(VERTICAL_SCROLL| NO_HORIZONTAL_SCROLL );
            vfmMain.add(hfm);
            add(vfmMain);
    

    Help, please.

    When you start to need as many managers to get the look you want, then you know that you should really create your own Manager.

    These two should help you to do:

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

    For example, I hacked together a "centeringManager" and the screen, which should do what you want.  But please use this as a reference sample, understand what he does and maybe even improve it.

    In production code, I would really remove the centeredManager and centering Manager across all fields and place them, but then you must code a manager which includes margins, which would confuse the point of this example - as a basic implementation of a Manager.

    Hope it's what you want.

    public final class CenteringScreen extends MainScreen {
    
        /**
         * verticallyCenteringManager takes one Field and positions it
         * centered in the space it has.
         */
        VerticalFieldManager centeringManager = new VerticalFieldManager() {
            protected void sublayout(int maxWidth, int maxHeight) {
                if ( this.getFieldCount() > 1 ) {
                    throw new RuntimeException("Expecting only one Field or Manager to be added");
                }
                if ( this.getFieldCount() == 1 ) {
                    Field f = this.getField(0);
                    layoutChild(f, maxWidth, maxHeight);
                    int requiredTopMargin = (maxHeight - f.getHeight())/2;
                    int requiredLeftMargin = (maxWidth - f.getWidth())/2;
                    setPositionChild(f, requiredLeftMargin, requiredTopMargin);
                    setExtent(maxWidth, maxHeight);
                } else {
                    setExtent(0, 0);
                }
            }
        };
    
        /**
         * Fields added to centeredManager will be displayed 'centered' vertically
         * regardless of orientation of screen and presence or absence
         * of virtual keyboard
         */
        VerticalFieldManager centeredManager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR);
    
        // Sample Fields to be added
        ButtonField sampleButton = new ButtonField("Button", ButtonField.FIELD_HCENTER);
        LabelField sampleLabel = new LabelField("Label", LabelField.FIELD_HCENTER);
        BasicEditField sampleBef = new BasicEditField("Text", "", 255, BasicEditField.FIELD_HCENTER);
    
        public CenteringScreen() {        
    
            super(Manager.NO_VERTICAL_SCROLL); // very important
            // The NO_VERTICAL_SCROLL means that the only Manager added to this Screen - centeringManager -
            // will be given as its maxHeight, the available screen height, regardless of
            // orientation or whether there is a virtual keyboard displayed
    
            // add Fields to centeredManager
            centeredManager.add(sampleButton);
            centeredManager.add(sampleLabel);
            centeredManager.add(sampleBef);
            centeringManager.add(centeredManager);
            this.add(centeringManager);
    
        }
    
    }
    
  • Cannot navigate back to the previous screen (screen cannot be closed with the ESC key)

    Hi all

    I create simple BB app with eclipse jde 4.6.1, here the code example.

    class myApplication extends UiApplication
    {
        // applicatione entry point
        public static void main(String[] args)
        {
            // create an instance of our app
            myApplication theApp = new myApplication();
            // "run" the app
            theApp.enterEventDispatcher();
        }
        // app constructor
        public myApplication()
        {
         myScreen screen = new myScreen();
            pushScreen(screen);
        }
    }
    

    where my screen is like this

    public class myScreen extends MainScreen implements ListFieldCallback {
    private Vector menu;
    private ListField menuList;
    private MenuItem menuItem = new MenuItem("Details",100,10){
    public void run(){
    int index = menuList.getSelectedIndex();
    if (index == 1){
    Dialog.alert("list  "+index+" selected");
    }
    }
    };
    public void drawListRow(ListField listField, Graphics graphics, int index,
    int y, int width) {
         ListField menulist = (ListField) listField;
         MenuRowManager rowManager = (MenuRowManager)menu.elementAt(index);
         rowManager.drawRow(graphics, 0, y, width, menulist.getRowHeight());
    }
    
    public myScreen(){
    super(DEFAULT_MENU|DEFAULT_CLOSE);
    setTitle(new LabelField("myScreen", LabelField.USE_ALL_WIDTH | DrawStyle.HCENTER));
    
    this.addMenuItem(menuItem);
    createListMenu();
    }
    
    public void createListMenu(){
    menu = new Vector();
    menuList = new ListField(){
    protected boolean keyChar(char key, int status, int time){
    if (key == Characters.ENTER){
    // open next window
    int index = getSelectedIndex();
    switch (index){
    case 0: //
    break;
    case 1: //
    break;
    case 2: //
    break;
    case 3: //
    break;
    default: // about
    break;
    }
    }
    return true;
    }
    };
    menuList.setCallback(this);
    menuList.setRowHeight(60);
    menuList.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
    
    // first item
    BitmapField mIcon = new BitmapField(Bitmap.getBitmapResource("image1.png"));
    LabelField lblM = new LabelField ("First list item", DrawStyle.LEFT);
    lblM.setFont(Font.getDefault().derive(Font.BOLD));
    MenuRowManager menuM = new MenuRowManager();
    menuM.add(mIcon);
    menuM.add(lblM);
    menu.addElement(menuM);
    
    // 2nd item
    BitmapField tIcon = new BitmapField(Bitmap.getBitmapResource("image2.png"));
    LabelField lblT = new LabelField("Theater Near Me", DrawStyle.LEFT);
    lblT.setFont(Font.getDefault().derive(Font.BOLD));
    MenuRowManager menuT = new MenuRowManager();
    menuT.add(tIcon);
    menuT.add(lblT);
    menu.addElement(menuT);
    
    add(menuList);
    }
    
    }
    

    and the definition of menuRowManager is like that

    public class MenuRowManager extends Manager
    {
        public MenuRowManager()
        {
            super(0);
        }
    
        // Causes the fields within this row manager to be layed out then
        // painted.
        public void drawRow(Graphics g, int x, int y, int width, int height)
        {
            // Arrange the cell fields within this row manager.
            layout(width, height);
    
            // Place this row manager within its enclosing list.
            setPosition(x, y);
    
            // Apply a translating/clipping transformation to the graphics
            // context so that this row paints in the right area.
            g.pushRegion(getExtent());
    
            // Paint this manager's controlled fields.
            subpaint(g);
    
            g.setColor(0x00CACACA);
            g.drawLine(0, 0, getPreferredWidth(), 0);
            //g.drawLine(10, 0, 10, getPreferredHeight());
    
            // Restore the graphics context.
            g.popContext();
        }
    
        // Arranges this manager's controlled fields from left to right within
        // the enclosing table's columns.
        protected void sublayout(int width, int height)
        {
            // set the size and position of each field.
            int fontHeight = Font.getDefault().getHeight();
            int preferredWidth = getPreferredWidth();
    
            // start with the Bitmap Field of menu icon
            Field field = getField(0);
            layoutChild(field, 48, 48);
            setPositionChild(field, 0, 6);
    
            // set the menu title label field
            field = getField(1);
            layoutChild(field, preferredWidth - 16, fontHeight+1);
            setPositionChild(field, 55, 30-fontHeight/2);
    
            setExtent(preferredWidth, getPreferredHeight());
        }
    
        // The preferred width of a row is defined by the list renderer.
        public int getPreferredWidth()
        {
            return Graphics.getScreenWidth();
        }
    
        // The preferred height of a row is the "row height" as defined in the
        // enclosing list.
        public int getPreferredHeight()
        {
            return 60;
        }
    }
    

    the problem is, when the first screen showed (pushed), I cannot "navigate back (close) the screen with ESC, won't my code?" Am I missing something here?

    Thanks in advance

    You want to substitute keyChar() into your custom domain.

    Don't forget that you must re - delegate all keystrokes that you do not consume.

  • Implementing custom listener for ListField

    I'm trying to implement a listener for a custom field I created that would launch a new screen when you click on the field. However, nothing happens when I click on the custom field. I use BlackBerry Java plug-in for Eclipse, JDK 1.3 and JRE 6.0. All my code is attached. MyScreen.java contains the code where I'm trying to implement a function fieldChanged.

    //MyApp.Java
    
    package mypackage;
    
    import net.rim.device.api.system.CodeModuleManager;
    import net.rim.device.api.ui.UiApplication;
    
    /**
     * This class extends the UiApplication class, providing a
     * graphical user interface.
     */
    public class MyApp extends UiApplication
    {
        /**
         * Entry point for application
         * @param args Command line arguments (not used)
         */
        public static void main(String[] args)
        {
            CodeModuleManager.promptForResetIfRequired();
    
            // Create a new instance of the application and make the currently
            // running thread the application's event dispatch thread.
            MyApp theApp = new MyApp();
            theApp.enterEventDispatcher();
        }
    
        /**
         * Creates a new MyApp object
         */
        public MyApp()
        {
            // Push a screen onto the UI stack for rendering.
            pushScreen(new MyScreen());
        }
    }
    
    //MyScreen.java
    
    package mypackage;
    
    import net.rim.device.api.ui.container.*; //for vertical manager
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FieldChangeListener;
    import net.rim.device.api.ui.Manager;
    //import net.rim.device.api.ui.Screen;
    import net.rim.device.api.ui.component.*;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.decor.BackgroundFactory;
    
    /**
     * A class extending the MainScreen class, which provides default standard
     * behavior for BlackBerry GUI applications.
     */
    public final class MyScreen extends MainScreen
    {
        /**
         * Creates a new MyScreen object
         */
        private CustomField cField;
    
        public MyScreen()
        {
            // Set the displayed title of the screen
            setTitle("My New App");
    
            cField = new CustomField("4.PNG","This is my 4th custom field!!");
            ButtonClickListener listener = new ButtonClickListener();
            cField.setChangeListener(listener);
            add(cField);
    
        }//MyScreen function
    
        class ButtonClickListener implements FieldChangeListener
        {
            public void fieldChanged(Field field, int context)
             {
                  //we need to determine which button was clicked
    
                  if(field == cField)
                      new SpeedBumpScreen();
    
             }
    
        }//ButtonClickListener
    
    }
    
    //CustomField.java
    
    package mypackage;
    
    import java.util.Vector;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.*;
    import net.rim.device.api.ui.component.*;
    
    class CustomField extends ListField implements ListFieldCallback {
        private Vector rows;
    
        public CustomField(String customImg, String customLabel) {
            super(0, ListField.MULTI_SELECT);
            setRowHeight(80);
            setEmptyString("Hooray, no items here!", DrawStyle.HCENTER);
            //setCallback(this);
    
            Bitmap p1 = Bitmap.getBitmapResource(customImg); 
    
            rows = new Vector();
    
            TableRowManager row = new TableRowManager();
    
            row.add(new BitmapField(p1));
    
            // SET THE item NAME LABELFIELD
            // if overdue, bold/underline
            LabelField item = new LabelField("item #" + customLabel,
                DrawStyle.ELLIPSIS);
    
            // overdue
            item.setFont(Font.getDefault().derive(
                Font.BOLD | Font.UNDERLINED));
            System.out.println("OVERDUE");
    
            row.add(item);
    
            // SET THE LIST NAME
            row.add(new LabelField("List Name #" + String.valueOf(1),
                DrawStyle.ELLIPSIS) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(0x00878999);
                    super.paint(graphics);
                }
            });
    
            // SET THE DUE DATE/TIME
            row.add(new LabelField("Due Date #" + String.valueOf(1),
                    DrawStyle.ELLIPSIS | LabelField.USE_ALL_WIDTH
                    | DrawStyle.RIGHT) {
                protected void paint(Graphics graphics) {
                    graphics.setColor(0x00878787);
                    super.paint(graphics);
                }
            });
    
            rows.addElement(row);
    
            setSize(rows.size());
    
        } //end public CustomField()
    
        // ListFieldCallback Implementation
        public void drawListRow(ListField listField, Graphics g, int index, int y,
                int width) {
            CustomField list = (CustomField) listField;
            TableRowManager rowManager = (TableRowManager) list.rows
                .elementAt(index);
            rowManager.drawRow(g, 0, y, width, list.getRowHeight());
        } //end drawListRow()
    
        private class TableRowManager extends Manager {
    
            public TableRowManager() {
                super(0);
            } //end pulic TableRowManager
    
            // Causes the fields within this row manager to be layed out then
            // painted.
            public void drawRow(Graphics g, int x, int y, int width, int height) {
                // Arrange the cell fields within this row manager.
                layout(width, height);
    
                // Place this row manager within its enclosing list.
                setPosition(x, y);
    
                // Apply a translating/clipping transformation to the graphics
                // context so that this row paints in the right area.
                g.pushRegion(getExtent());
    
                // Paint this manager's controlled fields.
                subpaint(g);
    
                g.setColor(0x00CACACA);
                g.drawLine(0, 0, getPreferredWidth(), 0);
    
                // Restore the graphics context.
                g.popContext();
            }//end drawRow()
    
            // Arranges this manager's controlled fields from left to right within
            // the enclosing table's columns.
            protected void sublayout(int width, int height) {
                // set the size and position of each field.
                int fontHeight = Font.getDefault().getHeight();
                int preferredWidth = getPreferredWidth();
    
                // start with the Bitmap Field of the priority icon
                Field field = getField(0);
                layoutChild(field, 32, 32);
                setPositionChild(field, 0, 0);
    
                // set the item name label field
                field = getField(1);
                layoutChild(field, preferredWidth - 16, fontHeight + 1);
                setPositionChild(field, 34, 3);
    
                // set the list name label field
                field = getField(2);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, 34, fontHeight + 6);
    
                // set the due time name label field
                field = getField(3);
                layoutChild(field, 150, fontHeight + 1);
                setPositionChild(field, preferredWidth - 152, fontHeight + 6);
    
                setExtent(preferredWidth, getPreferredHeight());
            }//end sublayout()
    
            // The preferred width of a row is defined by the list renderer.
            public int getPreferredWidth() {
                return Graphics.BLACK;
            }
    
            // The preferred height of a row is the "row height" as defined in the
            // enclosing list.
            public int getPreferredHeight() {
                return getRowHeight();
            }
    
        }// private class TableRowManager extends Manager 
    
        public Object get(ListField listField, int index) {
            // TODO Auto-generated method stub
            return null;
        }
    
        public int getPreferredWidth(ListField listField) {
            // TODO Auto-generated method stub
            return 0;
        }
    
        public int indexOfList(ListField listField, String prefix, int start) {
            // TODO Auto-generated method stub
            return 0;
        }
    
    } //end class CustomField extends ListField implements ListFieldCallback
    
    //SpeedBumpScreen.java
    
    package mypackage;
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.component.RichTextField;
    import net.rim.device.api.ui.container.MainScreen;
    
    public final class SpeedBumpScreen extends MainScreen
    {
        /**
         * Creates a new HelloWorldScreen object
         */
        SpeedBumpScreen()
        {
            // Set the displayed title of the screen
            setTitle("Speed bump screen");
    
            // Add a read only text field (RichTextField) to the screen.  The
            // RichTextField is focusable by default. Here we provide a style
            // parameter to make the field non-focusable.
            add(new RichTextField("This is the speed bump screen!", Field.NON_FOCUSABLE));
        }
    
    }
    

    In addition, there is nothing in the ListField that will actually generate an event.

    Here is a simple extension to the ListField which will make "clickable".  In your FieldChangeListener you can use getSelectedindex to determine which line has the focus.

    Please ask if this isn't clear:

    public class ClickableListField extends ListField {
    
        public ClickableListField(int numberOfRows) {
            super(numberOfRows);
        }
    
        protected boolean navigationClick(int status, int time) {
            this.fieldChangeNotify(2);
            return true;
        }
    
        protected boolean touchEvent(TouchEvent message) {
            int x = message.getX( 1 );
            int y = message.getY( 1 );
            if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
                    // Outside the field
                    return false;
            }
            // If click, process Field changed
            if ( message.getEvent() == TouchEvent.CLICK ) {
                this.fieldChangeNotify(2);
                return true;
            }
            return super.touchEvent(message);
        }
    
    }
    
  • How to set horizontal scrolling to horizontal field Manager when fields are added using a loop for?

    The following code snippet contains a horizontal field Manager to which are added five buttons.

    1. I can't the value of horizontal scrolling to horizontal management Manager because of who I am not able to access the keys 4 and 5.

    2. usually, we put horizontal scrolling in the following way:

    container = new HorizontalFieldManager(USE_ALL_WIDTH|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR);
    

    3. so I also tried setting of horizontal scrolling in the following way

       container = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL|Manager.HORIZONTAL_SCROLLBAR)
                {
    
                    protected void sublayout(int maxWidth, int maxHeight) {
    
                        Field field = null;
                        int x = 0;
                        int y = 0;
                        int maxFieldHeight = 0;
                        int maxFieldWidth = 0;
                        for (int i = 0; i < getFieldCount(); i++)
                        {
                            field = getField(i);
                            layoutChild(field, maxWidth, maxHeight);
                            setPositionChild(field, x/*width-field.getWidth()*/,y);
    
                            x+=field.getWidth();
    
                            maxFieldWidth = maxFieldWidth + field.getWidth();
                            System.out.println("field width"+field.getWidth());
                            System.out.println(" max field width"+maxFieldWidth);
    
                            if(i==0)
                            {
                                maxFieldHeight = field.getHeight(); // height set of the first button since all components have the same height
                            }
                        }
                        System.out.println("final max field width"+maxFieldWidth);
    
                        setExtent(maxFieldWidth, maxFieldHeight);
    
                    }
                };
    

    but it's not working.

    4 I found this property: (position) horizontalFieldManager.setHorizontalScroll; that contains the parameterioo where the post is supposed to be the new horizontal scroll position. I tried passing the coordinate x of horizontal field Manager, but it does not work. I should pass as a parameter position?

    HorizontalFieldManager container = new HorizontalFieldManager()
    {
        protected void sublayout(int maxWidth, int maxHeight)
        {
            Field field = null;
            int x = 0;
            int y = 0;
            int maxFieldHeight = 0;
            for (int i = 0; i < getFieldCount(); i++)
            {
                field = getField(i);
                layoutChild(field, maxWidth, maxHeight);
                setPositionChild(field, x,y);
                x+=field.getWidth();
                if(i==0)
                {
                    maxFieldHeight = field.getHeight(); // height set of the first button since all components have the same height
                }
            }
    
            setExtent(Display.getWidth(), maxFieldHeight);
    
        }
    };
    
    ButtonField button1 = new ButtonField("Button1");
    ButtonField button2 = new ButtonField("Button2");
    ButtonField button3 = new ButtonField("Button3");
    ButtonField button4 = new ButtonField("Button4");
    ButtonField button5 = new ButtonField("Button5");
    
    container.add(button1);
    container.add(button2);
    container.add(button3);
    container.add(button4);
    container.add(button5);
    
    add(container);
    

    Need your valuable comments and suggestions. Please help me.

    I think that there is a bug in the sublayout (your HorizontalFieldManager 0 mode.  Given that the code did what I think WHAT HFM will do anyway, I recommend that you try to do this with a standard HFM, using this style:

    Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR

    Let us know how you go.

    When I have more time I'll explain the bug, but if you want to investigate something, be aware that the maximum size that you can use in setExtent are the values that are passed to sublayout.  Compare the width as you try to define in setExtent whose width is increased.

Maybe you are looking for

  • Please help... can't connect - countless entered

    Out of the standby mode and when you are prompted to enter my password: I try to enter my password and types of countless points (it's like it's stuck key or something) of the computer and I can't stop it.  Then the part of logon screen starts shakin

  • AppStore; new ID

    When I created a new account, I have problems with updates. Writes that the app is purchased for another account (for her, I don't have access). I can't update free apps: Xcode, a Note and others. When I deleted the computer application in the appsto

  • My HP 6910P becomes very hot

    Hello everyone My HP 6910P is in strangerly that he gets very very hot after about 15 minutes. He's left-handed side ports also have become very hot especially the usb ports. I'm very worried about it. I'll be very grateful to you if you give me the

  • Inaccessible files

    I bought a second hand computer running XP Home edition of the estate of a friend. end on it, I discovered a subfolder that denies access. Does anyone have an idea how to get around this problem?

  • I get the error message when I try right-click on applications

    Original title: Hello, peeps__I I have this problem and can't you right-click on my apps___gz Signature of the problem:Problem event name: BEX64Application name: explorer.exeApplication version: 6.1.7600.16450Application timestamp: 4aebab8dFault Modu