getPreferredHeight() and getPreferredWidth()

So, can someone please explain how these functions?

Whenever I read an article or howto on custom layout managers is the only way that these features are specified "returns the height of favorite."

OH! That's what the name of the function has already distributed. I just want to know how these functions have an effect on the buttons or other items on the screen...

Thanks for explaining the buddies!

the height and width of a field are known that once the field has been ask outed.

'demand' Manager each field how much space he would like and trying to stuff them all together in a given area.

in most cases preferred values are those used on the screen. the exception is if there is not enough space for all.

Tags: BlackBerry Developers

Similar Questions

  • Question regarding setExtent and getPreferredWidth for the custom field

    I am trying to understand the difference between getPreferredWidth and setExtent, which relate to the width of a custom field.

    I create a field that may be greater than the width of the screen. The field is made up of cells (for example columns and lines or cells, such as a table). The cells contain text, shapes, lines, color, etc. When I display the field I only paint the visible columns on the screen and allow the user to use the trackball to accomplish the columns out of the screen.

    At present, getPreferredWidth returns the total width of the field without all the empty columns, is longer than the width of the screen. I use the same value in setExtent for width. GetPreferredWidth must return the size of the field that is painted on the screen - the total width less the width of the columns out of the screen? I have the same question about setExtent - width either in total, longer than the screen width or the width of the part of the field that is painted on the screen?

    If I use the width of what is painted on the screen or the other of these methods, then the width changes when the user scrolls through the field. As the user scrolls, I calculate the number of columns will agree to a width of the screen and paint these columns. Is it a problem to have the PreferredWidth and the setExtent change width? I read that setExtent is called only when the Manager sets this field, so that the changes will not be recognized.

    It seems to work in two ways in a few simple tests, but I was just curious as the value of width that is right.

    Thank you!

    Mark

    When a field has changed in a way that requires the update of the screen (for example, after scrolling offset changes), simply call invalidate() from this area. That will eventually lead to paint (Graphics) for the field. At this point, you return the update field. (If only part of a field - as a single cell - needs to be updated, there invalidate() versions that accept arguments where, for efficiency, you can limit the update for just this part.)

    If I understand your needs, you can achieve the effect desired in the paint method. You can use the current dimensions of the field, the cutting of the graphics area, and your internal roll compensates to decide what to paint and what to delete. Let your custom field leave white space where you decide of doesn't make is not part of a cell. There is no need to change the scope of the field.

    If you go about it by changing the dimensions of the field, and then you ask the system to play much more work he has to do. If the custom field is the only field on the screen, it won't make much difference in the behavior (although there may be performance). With more than one field, it can be weird effects. For example, suppose that your custom field is one of several fields in a HorizontalFieldManager and you change the field width. When the HorizontalFieldManager recalculates its own layout, it will change the horizontal position of the fields to the right. The effect on the user, I think, would be really confusing: as the custom field parade, parties to the right of the screen could bounce left and right as the changed width field. I can't imagine that's what you want.

    Here's another way to think about this: absent some bit of style, your custom field would prefer be exactly wide and high enough to show all without scrolling. So the width and height would be based on adding the appropriate cell widths and heights, regardless of what actually is on the display. (It's also a long time that you do not have something fanciful.) If the optimum height is a function of the width available - as with sheathed on the line of text - you would implement this logic in the layout method. You then have no use for autonomous preferred width and height).

  • ButtonField getPreferredHeight/getPreferredWidth

    I use a clean layout manager (similar to FlowFieldManager, but with a uniform spacing Manager). Never had a problem until I added buttonfields only.
    Here is a screenshot of the result:

    When I debug the code, I discovered that getPreferredHeight and getPreferredWidth have both return different values from the values they take on the screen.
    In the picture you can see the button being 27 pixels high, which is the getPreferredHeight value returns. 27 is also the height of the content text box.
    getPreferredWidth returns 76, on the screen, the button takes about 130 pixels.

    Analyzing the output of the debugger, further, I see that the containcs of ButtonField several bitmaps. If we total the scopes of these bitmaps, you get the values I measured on the screen:
    _bitmapLeft width 28 and _bitmapRight 28. If we add the width by default, you get 76 + 28 + 28 = 132!

    At the end: How can I recover the preferred width and height at disposal the buttonFields correctly?

    I strongly recommend calling layoutChild on the first button, and then getting it is extended, subtract the thickness resulting in overall width and spend this width in the next layoutChild. You can then use the resulting width of the two buttons to call setPositionChild. The same technique can be used for the height.

    * edit * I should clarify why you can call layoutchild. This routine performs operations such as grabbing the BitmapBorder (not accessible to the public) and appellant getIndent() (once again not publicly available) and getMarginTop() getMarginBottom() to determine the appropriate width and height that the key should be in with the Manager. It then calls the button layout, and the button will define its own measure of the height and the desired width. You can then use this information to determine where you want to position in the Manager. I hope this helps!

  • Extended method of field paint will not called

    I would go to a field and would like to paint something there.

    By extending the field I must apply setLayout (int x, int y) wcich get is called successfully.

    Thing strange number one: x is 360 (that's fine because I have it returned by getPreferredWitdh), there is

    1073741803 which is more hell? In getPreferredHeight I returned 480...

    Second, my method of painting is not called at all! See code below.

    You forgot to call your layout() setExtent() while defining the scope of the field is the main object of the layout () - to tell the parent Manager how much space you wish to occupy. Without putting your width and height are (0, 0), which explains why your parent Manager never calls object of your field.

    The fact that you get almost unlimited height in your layout() is also easy to explain: you probably use screen that has default VERTICAL_SCROLL.  And managers who have VERTICAL_SCROLL allocates Integer.MAX_VALUE > 1 pixel at the start for their children.  Your LabelField consumed 14 of this value (using setExtent (textWidth, 14), of course) and then screen offered the rest of your domain.

    Also note that getPreferredHeight() and getPreferredWidth() are ignored by the vast majority of managers and fields.

  • Popup screen problems

    I've tried using the search tool and google my whole day, but I can't seem to find the answer to these two problems.

    1. I'm positioning my pop-up screen in the middle of the screen. But as you can see in the image below it is nowhere near the Center.

    2. I'm trying to focus my two buttons in the middle of the popup screen with a verticalfieldmanager, but somehow it is fondant a position according to the width, I don't know what.

    Here is the code:

    private final static int _Width = 200;private final static int _Height = 200;private final static int _X = (Display.getWidth() - _Width) >> 1;private final static int _Y = (Display.getHeight() - _Height) >> 1;public class NetworkSettingScreen extends PopupScreen{
    
    public NetworkSettingScreen(){   super( new VerticalFieldManager());   LabelField lf = new LabelField("Network Settings", DrawStyle.HCENTER);    SeparatorField sf = new SeparatorField();         CheckboxField cbf1 = new CheckboxField(" WiFi", true);    CheckboxField cbf2 = new CheckboxField(" GPRS/Edge/3G", true);
    
      VerticalFieldManager vfm = new VerticalFieldManager(HorizontalFieldManager.FIELD_HCENTER);    ButtonField bf1 = new ButtonField("Save", DrawStyle.HCENTER); ButtonField bf2 = new ButtonField("Cancel", DrawStyle.HCENTER);   vfm.add(bf1); vfm.add(bf2);
    
      //add UI components to Pop-up screen  add(lf);  add(sf);  add(cbf1);    add(cbf2);    add(vfm);}
    
    public void sublayout(int width, int height){   super.sublayout(width, height);   setExtent(_Width, _Height);           setPosition(_X, _Y);}}//end of class
    

    http://i55.Photobucket.com/albums/G152/chengbang69/screenshot.jpg

    any help would be appreciated

    Hey chengbang69,

    I modified your code to obtain the expected results,

    final class NetworkSettingScreen extends PopupScreen
    {
        private final static int _Width = 200;
        private final static int _Height = 200;
        private final static int _X = (Display.getWidth() - _Width) >> 1;
        private final static int _Y = (Display.getHeight() - _Height) >> 1;
    
    public NetworkSettingScreen()
    {
        super( new VerticalFieldManager());
        LabelField lf = new LabelField("Network Settings", LabelField.FIELD_HCENTER);
        SeparatorField sf = new SeparatorField();
        CheckboxField cbf1 = new CheckboxField(" WiFi", true);
        CheckboxField cbf2 = new CheckboxField(" GPRS/Edge/3G", true);
    
        VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
        ButtonField bf1 = new ButtonField("Save", ButtonField.FIELD_HCENTER);
        ButtonField bf2 = new ButtonField("Cancel", ButtonField.FIELD_HCENTER);
        vfm.add(bf1);
        vfm.add(bf2);
    
        //add UI components to Pop-up screen
        add(lf);
        add(sf);
        add(cbf1);
        add(cbf2);
        add(vfm);
    }
    public int getPreferredWidth() {
        return _Width;
    }
    public int getPreferredHeight() {
        return _Height;
    }
    
    public void sublayout(int width, int height)
    {
        super.sublayout(getPreferredWidth(), Integer.MAX_VALUE);
        setExtent(getPreferredWidth(), getPreferredHeight());
        setPosition(_X, _Y);
    }
    }//end of class
    

    The reason why you need to replace getPreferredHeight() and getPreferredWidth() is due to all subcalls and sublayouts which actually occur when you call super.sublayout. It will then use the 'default' screen page or getPreferredWidth/height.

    Just a friendly recommendation, adjusting the size of a screen to a static value is effective only if you also check the size of the font, currently if the user has a font above average size, a part of the text will not be seen, so, technically, the most effective way is to have the JAVA virtual machine to manage the resizing/flaking itself This can be done by simply using the same code that I posted above, however remove the substitution on sublayout, the width will be slightly larger that you set but at least you won't encounter unknowns.

    Hope this helps,

    Concerning

    André

  • LabelField and field in a HorizontalFieldManager separator

    Hey there,

    I try to get a LabelField and a concatinated separator field, so I can have a followed by legend of a line separator

    as:

    Legend-

    The problem is that when I add the seperator line after the tag, I can't see it at all.

    any idea on what I should do?

    Thank you...

    Try something like this:

            LabelField label = new LabelField("Caption ");
            final int labelWidth = label.getPreferredWidth();
            SeparatorField separatorField = new SeparatorField()
            {
                public int getPreferredWidth()
                {
                    return Display.getWidth() -  labelWidth;
                }
                protected void layout( int width, int height )
                {
                    super.layout(getPreferredWidth(),
                                 getPreferredHeight());
                    setExtent(getPreferredWidth(), getPreferredHeight());
                }
            };
                    HorizontalFieldManager hfm = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
            VerticalFieldManager vfmLeft = new VerticalFieldManager();
            VerticalFieldManager vfmRight = new VerticalFieldManager(Field.FIELD_VCENTER);
            vfmLeft.add(label);
            vfmRight.add(separatorField);
            hfm.add(vfmLeft);
            hfm.add(vfmRight);
    

    Concerning

    Bika

  • Add ButtonField on BitmapFiled

    Hi all

    I tried to use this code to add BitmapButtonField on BitmapField but I couldn't use it.

    Ant one can help me?

    package mypackage;
    
    import com.operations.images.ImageManipulator;
    
    import net.rim.device.api.system.Application;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.system.JPEGEncodedImage;
    import net.rim.device.api.ui.TouchEvent;
    import net.rim.device.api.ui.TouchGesture;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.component.BitmapField;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.Dialog;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.SeparatorField;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    /**
     * A class extending the MainScreen class, which provides default standard
     * behavior for BlackBerry GUI applications.
     */
    public final class MyScreen extends MainScreen {
    
        private static int rotatedAngle = 360;
    
        // byte[] rrr = resizeImage(Bitmap.getBitmapResource("gear.png"),
        // Display.getWidth(), Display.getHeight() / 2);
        // Bitmap originalBmp = Bitmap.createBitmapFromBytes(rrr, 0, rrr.length, 1);
        Bitmap originalBmp = Bitmap.getBitmapResource("[email protected]");
        BitmapField rotatedBitmap = new BitmapField(originalBmp);
    
        private BitmapButtonField buttonField1 = new BitmapButtonField(
                Bitmap.getBitmapResource("images_1.png"));
        private BitmapButtonField buttonField2 = new BitmapButtonField(
                Bitmap.getBitmapResource("images_2.png"));
    
        VerticalFieldManager bmpManager = new VerticalFieldManager(USE_ALL_WIDTH
                | NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL) {
    
            public int getPreferredHeight() {
                return rotatedBitmap.getHeight();
            };
    
            public int getPreferredWidth() {
                return rotatedBitmap.getWidth();
            };
    
            protected void sublayout(int maxWidth, int maxHeight) {
    
                layoutChild(rotatedBitmap, originalBmp.getWidth(),
                        originalBmp.getHeight());
                layoutChild(buttonField1, buttonField1.getPreferredWidth(),
                        buttonField1.getPreferredHeight());
                layoutChild(buttonField2, buttonField2.getPreferredWidth(),
                        buttonField2.getPreferredHeight());
    
                setPositionChild(rotatedBitmap, 0, 0);
                setPositionChild(buttonField1, 0, 50);
                setPositionChild(buttonField2, 50, 50);
    
                super.sublayout(getPreferredWidth(), getPreferredHeight());
                setExtent(getPreferredWidth(), getPreferredHeight());
    
            };
        };
    
        VerticalFieldManager manager = new VerticalFieldManager(USE_ALL_WIDTH
                | NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL) {
    
            public int getPreferredHeight() {
                return Display.getHeight() - bmpManager.getPreferredHeight();
            };
    
            public int getPreferredWidth() {
                return Display.getWidth();
            };
        };
    
        /**
         * Creates a new MyScreen object
         */
        public MyScreen() {
            super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
            // Set the displayed title of the screen
            setTitle("Test Animation");
    
            bmpManager.add(rotatedBitmap);
            bmpManager.add(buttonField1);
            bmpManager.add(buttonField2);
    
            manager.add(new SeparatorField());
            manager.add(new SeparatorField());
            manager.add(new LabelField(" label 1 "));
            manager.add(new LabelField(" label 2 "));
            manager.add(new LabelField(" label 3 "));
    
            add(bmpManager);
    
            add(manager);
    
        }
    
        protected boolean touchEvent(TouchEvent message) {
            switch (message.getEvent()) {
            case TouchEvent.CLICK:
                // invokeDialog("-->CLICK");
                return true;
            case TouchEvent.DOWN:
                // invokeDialog("-->DOWN");
                return true;
    
            case TouchEvent.GESTURE:
                TouchGesture gesture = message.getGesture();
                int gestureCode = gesture.getEvent();
    
                if (gesture.getSwipeDirection() == TouchGesture.SWIPE_NORTH) {
                    invokeDialog("swip north : " + gesture.getSwipeAngle() + " , "
                            + gesture.getSwipeMagnitude());
                } else if (gesture.getSwipeDirection() == TouchGesture.SWIPE_SOUTH) {
                    invokeDialog("swip south : " + gesture.getSwipeAngle() + " , "
                            + gesture.getSwipeMagnitude());
                } else if (gesture.getSwipeDirection() == TouchGesture.SWIPE_EAST) {
                    if ((message.getX(1) >= bmpManager.getContentRect().x && message
                            .getX(1) <= bmpManager.getContentRect().width)
                            && (message.getY(1) >= bmpManager.getContentRect().y && message
                                    .getY(1) <= bmpManager.getContentRect().height)) {
    
                        // invokeDialog("swip east : " + gesture.getSwipeAngle()
                        // + " , " + gesture.getSwipeMagnitude());
                        rotate(true);
    
                    }
                } else if (gesture.getSwipeDirection() == TouchGesture.SWIPE_WEST) {
                    if ((message.getX(1) >= bmpManager.getContentRect().x && message
                            .getX(1) <= bmpManager.getContentRect().width)
                            && (message.getY(1) >= bmpManager.getContentRect().y && message
                                    .getY(1) <= bmpManager.getContentRect().height)) {
    
                        // invokeDialog("x = " + bmpManager.getContentRect().x +
                        // " , "
                        // + bmpManager.getContentRect().width + " \ny = "
                        // + bmpManager.getContentRect().y + " , "
                        // + bmpManager.getContentRect().height + "\n mx = "
                        // + message.getX(1) + " , " + message.getY(1));
                        // invokeDialog("swip west : " + gesture.getSwipeAngle()
                        // + " , " + gesture.getSwipeMagnitude());
                        rotate(false);
    
                    }
                }
    
                return true;
    
            case TouchEvent.MOVE:
                // int moveSize = message.getMovePointsSize();
                // int[] x_points;
                // int[] y_points;
                // int[] time_points;
                // int size = message.getMovePointsSize();
                // x_points = new int[size];
                // y_points = new int[size];
                // time_points = new int[size];
                // message.getMovePoints(1, x_points, y_points, time_points);
                //
                // if (x_points.length >= 50) {
                // invokeDialog("-->move : " + size);
                // }else if(x_points.length == 2){
                // invokeDialog("-->move : ssss = " + 2);
                // }
                return true;
            }
            System.out.println("PRINT ME SOMETHING IN ANY CASE");
            return false;
        }
    
        private void rotate(final boolean east) {
    
            synchronized (Application.getEventLock()) {
                UiApplication.getUiApplication().invokeLater(new Runnable() {
    
                    public void run() {
                        // wipe east
                        if (east) {
                            // if (rotatedAngle >= 0) {
                            for (int i = 0; i < 45; i += 1) {
                                try {
                                    rotatedAngle -= i;
                                    rotatedBitmap.setBitmap(ImageManipulator
                                            .rotate(originalBmp, rotatedAngle));
                                    bmpManager.invalidate();
                                    // bmpManager.deleteAll();
                                    // bmpManager.add(new
                                    // BitmapField(rotatedBitmap));
    
                                    // Thread.sleep(100);
                                } catch (Exception e) {
                                }
                            }
                            // }
                        } else {
                            // swipe weast
                            // if (rotatedAngle <= 360) {
                            for (int i = 0; i < 45; i += 1) {
                                try {
                                    rotatedAngle += i;
                                    rotatedBitmap.setBitmap(ImageManipulator
                                            .rotate(originalBmp, rotatedAngle));
                                    bmpManager.invalidate();
                                    // bmpManager.deleteAll();
                                    // bmpManager.add(new
                                    // BitmapField(rotatedBitmap));
    
                                    // Thread.sleep(100);
                                } catch (Exception e) {
                                }
                            }
                            // }
    
                        }
                    }
                });
    
            }
        }
    
        public static void invokeDialog(final String msg) {
            UiApplication.getUiApplication().invokeLater(new Runnable() {
    
                public void run() {
                    Dialog.inform(msg);
                }
            });
        }
    
        public static byte[] resizeImage(Bitmap srcBitmap, int width, int height) {
            // int width = 0;
            // int height = 0;
            // Bitmap srcBitmap = Bitmap.createBitmapFromBytes(image, 0,
            // image.length,
            // 1);
            // if (srcBitmap.getWidth() > srcBitmap.getHeight()) {
            // width = widthT;
            // height = (widthT * srcBitmap.getHeight()) / srcBitmap.getWidth();
            // } else if (srcBitmap.getWidth() < srcBitmap.getHeight()) {
            // height = heightT;
            // width = (height * srcBitmap.getWidth()) / srcBitmap.getHeight();
            // } else {
            // width = widthT;
            // height = heightT;
            // }
            Bitmap destBitmap = new Bitmap(width, height);
            srcBitmap.scaleInto(destBitmap, Bitmap.FILTER_BILINEAR);
            JPEGEncodedImage encoded = JPEGEncodedImage.encode(destBitmap, 100);
            return encoded.getData();
        }
    }
    

    Thank you

    I tried to improve my code and I found the solution

    /**
     * @author : Ahmed Shoeib
     * @description : add BitmapButtonField over BitmapField
     */
    public final class MyScreen extends MainScreen {
    
        Bitmap originalBmp = Bitmap.getBitmapResource("[email protected]");
        BitmapField rotatedBitmap = new BitmapField(originalBmp);
    
        BitmapButtonField buttonField1 = new BitmapButtonField(
                Bitmap.getBitmapResource("images_1.png"));
        BitmapButtonField buttonField2 = new BitmapButtonField(
                Bitmap.getBitmapResource("images_2.png"));
    
        Manager mainManager = new Manager(USE_ALL_WIDTH | NO_HORIZONTAL_SCROLL
                | NO_VERTICAL_SCROLL) {
    
            public int getPreferredHeight() {
                return rotatedBitmap.getHeight();
            };
    
            public int getPreferredWidth() {
                return rotatedBitmap.getWidth();
            };
    
            protected void sublayout(int width, int height) {
    
                setPositionChild(rotatedBitmap, 0, 0);
                layoutChild(rotatedBitmap, rotatedBitmap.getPreferredWidth(),
                        rotatedBitmap.getPreferredHeight());
    
                setPositionChild(buttonField1, getPreferredWidth() / 2, 0);
                layoutChild(buttonField1, buttonField1.getPreferredWidth(),
                        buttonField1.getPreferredHeight());
    
                setPositionChild(buttonField2, getPreferredWidth() / 2,
                        getPreferredHeight() / 2);
                layoutChild(buttonField2, buttonField2.getPreferredWidth(),
                        buttonField2.getPreferredHeight());
    
                setExtent(getPreferredWidth(), getPreferredHeight());
            }
        };
    
        VerticalFieldManager bottomManager = new VerticalFieldManager(USE_ALL_WIDTH
                | NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL) {
    
            public int getPreferredHeight() {
                return Display.getHeight() - mainManager.getPreferredHeight();
            };
    
            public int getPreferredWidth() {
                return Display.getWidth();
            };
        };
    
        /**
         * Creates a new MyScreen object
         */
        public MyScreen() {
            super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
            // Set the displayed title of the screen
            setTitle("Test Animation");
    
            mainManager.add(rotatedBitmap);
            mainManager.add(buttonField1);
            mainManager.add(buttonField2);
    
            bottomManager.add(new LabelField("fffffffffff"));
            bottomManager.add(new LabelField("fffffffffff"));
            bottomManager.add(new LabelField("fffffffffff"));
    
            add(mainManager);
            add(bottomManager);
    
        }
    
    }
    

    Thank you

  • Someone please send me an example how to implement the sublayout method

     public void displist(StringTokenizerDemo refdata)
       {
    
           /*while(refdata.hasMoreTokens())
           {
               refdata.nextToken(); // Consume unwanted input
               String modelName = refdata.nextToken().trim();
               refdata.nextToken();
               refdata.nextToken();
                listField.add(modelName);
    
           }*/
    
           while(refdata.hasMoreTokens())
           {
               String temp = refdata.nextToken().trim();
               String pressure = refdata.nextToken().trim();
               Object[] row = {temp, pressure};
               _tableModel.addRow(row);          
    
           }
           TableView tableView = new TableView(_tableModel);
           tableView.setDataTemplateFocus(BackgroundFactory.createLinearGradientBackground(Color.PURPLE, Color.PINK, Color.YELLOW, Color.RED));
           TableController tableController = new TableController(_tableModel, tableView);
           tableController.setFocusPolicy(TableController.ROW_FOCUS);
           tableView.setController(tableController);
    
           DataTemplate dataTemplate = new DataTemplate(tableView, NUM_ROWS, NUM_COLUMNS)
           {
               /**
                * @see DataTemplate#getDataFields(int)
                */
               public Field[] getDataFields(int modelRowIndex)
               {
    
                   Object[] data = (Object[]) (_tableModel.getRow(modelRowIndex));
                   Field[] fields = { new LabelField((String) data[0]), new LabelField((String) data[1])};
                   return fields;
               }
           };
    
           dataTemplate.useFixedHeight(false);
    
           // Define regions and row height
           dataTemplate.setRowProperties(0, new TemplateRowProperties(ROW_HEIGHT));
           for(int k = 0; k < NUM_COLUMNS; k++)
           {
               dataTemplate.createRegion(new XYRect(k,0,1,1));
               dataTemplate.setColumnProperties(k, new TemplateColumnProperties(Display.getWidth()/NUM_COLUMNS));
           }
    
           // Apply the template to the view
    
           tableView.setDataTemplate(dataTemplate);
           vfm.add(tableView);
           filteredList.addDataSet(0, temperature, "Temperature", BasicFilteredList.COMPARISON_IGNORE_CASE);         
    
           // Create AutoCompleteFields
    
           AutoCompleteField autoCompleteField = new AutoCompleteField(filteredList, AutoCompleteField.LIST_STATIC | AutoCompleteField.LIST_DROPDOWN);
    
           // Add the AutoCompleteFields to the screen           
    
           //add(new LabelField("Choose a Value"));
           vfm.add(autoCompleteField);
    
       }
    

    In my application I am stretching from Verticalmanager to my class and display data in tableview.

    but the problem is that all the data is displayed with the scroll bar. To get the scroll for the tableview bar

    I sends you only (code tableview) if someone meets me, I want to paste all of the code.

    Please answer

    Please stand to be corrected if I'm wrong, you want to set the height of a manager who is unscrollable, in a Manager, a list field must be added, which is scrollable. First make the screen unscrollable by great call (Manager.No_VERTICAL_SCROLL); Then create a handler, override its methods getPreferredWidth(), getPreferredHeight() and sublayout(), as below:

    mainManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL){
                public int getPreferredWidth()
                {
                    return super.getPreferredWidth();
                }
                public int getPreferredHeight()
                {
                                    // fixed height
                    return height;
                }
                protected void sublayout( int maxWidth, int maxHeight )
                {
                    super.sublayout(getPreferredWidth(),getPreferredHeight());
                    setExtent(getPreferredWidth(),getPreferredHeight());
                }
            };
    

    mainmanager add to your list.

  • Adding fix size backgorund to area manager

    Hello, I want to resize my backgorund image to fit in the domain manager and then used it as the background.

    Here is my code

    HorizontalFieldManager titleMngr = new HorizontalFieldManager();
    LabelField labelLogin = new LabelField("Device Activaiton");Bitmap panelTopBGBitmap = Bitmap.getBitmapResource("_background.png");
    Bitmap panelTopBGResBitmap =  GPATools.ResizeTransparentBitmap(panelTopBGBitmap, titleMngr.getPreferredWidth(), titleMngr.getPreferredHeight(),
                    Bitmap.FILTER_LANCZOS, Bitmap.SCALE_STRETCH);
    Background panelTopBG = BackgroundFactory.createBitmapBackground(panelTopBGResBitmap,0,0,Background.REPEAT_NONE);
    
    titleMngr.setBackground(panelTopBG);
    titleMngr.add(labelLogin);
    add(titleMngr);
    

    titleMngr.getPreferredHeight () and titleMngr.getPreferredWidth () always return me the value 0.

    How can I get the exact size of titleMngr? Please

    move titleMngr.add (labelLogin); directly under the labelfield constructor.
    Check to see if you still get 0 Manager.

  • background of the label

    I have a series of labels for which I change the background color using the paint method. Now the problem is I set a touch first and then that labels when I move the cursor to the button label, only a small part of the label background color change not the width of the entire label. Actuall Graphics considering the width of button above to set the color of the label... Can someone tell me how to set this

    Thanks for responding... .but now my problem is solved... Inside the paint method, I define solidbackgroound() and setbackgroundcolor() like this:

    Here the content is an array of fields of the label.

    content [i] = new CustomLabelField (s, 1449770, 22.0) {}
               
    public int getPreferredHeight()
    {
    Return (30);
    }
    public int getPreferredWidth()
    {
    Return (210);
    }
    protected void sublayout (int maxWidth, maxHeight int)
    {
    Super.Layout (getPreferredWidth (), getPreferredHeight ());
    setExtent (getPreferredWidth (), getPreferredHeight ());
    }
                    
    public void paint (Graphics graphics)
    {
    //.. Blue...
    if(Focus[j]==1)
    {
                        
    Background bg = BackgroundFactory.createSolidTransparentBackground (0xF0F0F1, 50);
    setBackground (bg);
    graphics.setBackgroundColor (1535207);
    Graphics.Clear (0, 0, 210, 210);
                         
                         
    } else {}
                            
    }
    Super.Paint (Graphics);
    }
                
    };

  • How to change the width of editfield in blackberry java

    Hi, blackberry has,

    I want to change the width of editfield... can someone tell me how I can do

    Hi Ludovic,.

    use TableLayoutManager and adjust the width of the field (based on no. added columns) for your screen.

    I don't get your condition, but if you want to insert fields so that it will adjust the space then use RoundedPanel and you can add a tablelayoutmanager to this Panel.

    /*
     * RoundedPanel.java
     *
     * © , 2003-2008
     * Confidential and proprietary.
     */
    
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Color;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    import net.rim.device.api.system.Display;
    
    /**
     *
     */
    public class RoundedPanel extends VerticalFieldManager {
        private int _heightBtmIncr = 0;
        private int color = Color.WHITE;
        private String str = null;
    
        public RoundedPanel() {
            super(Manager.VERTICAL_SCROLL);
        }
    
        public RoundedPanel(int heightBtmIncr) {
            super(Manager.VERTICAL_SCROLL);
            _heightBtmIncr = heightBtmIncr;
        }
    
        public RoundedPanel(int color , String str) {
    
            super(Manager.VERTICAL_SCROLL);
            this.str = str;
            this.color = color;
        }
    
        public void paint(Graphics g) {
            g.setBackgroundColor(Color.LIGHTGREY);
            int initialColor = g.getColor();
            g.setColor(Color.LIGHTGREY);
            g.fillRect(0, 0, this.getPreferredWidth(), this.getHeight());
            g.setColor(color);
            g.fillRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 17, 17);
            g.setColor(Color.DARKGRAY);
            g.drawRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 17, 17);
            g.setColor(initialColor);
            super.paint(g);
        }
    
        public void sublayout(int maxWidth, int maxHeight) {
            super.sublayout(maxWidth, Integer.MAX_VALUE);
            int fieldCount = getFieldCount();
            int x = 12;
            int y = 10;
            Field child = null;
    
            for (int i = 0; i < fieldCount; i++) {
                child = this.getField(i);
                setPositionChild(child, x, y);
                layoutChild(child, getFieldWidth(child), Integer.MAX_VALUE);
                int childHeight = getFieldHeight(child);
                y = y + childHeight;
            }
    
            this.setExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
            setVirtualExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
        }                  
    
        private int getFieldWidth(Field f) {
            return Math.min(Math.max(Math.max(f.getContentWidth(), f.getWidth()), f.getPreferredWidth()), this.getPreferredWidth() - 12);
        }
    
        private int getFieldHeight(Field f) {
            return Math.max(Math.max(f.getContentHeight(), f.getHeight()), f.getPreferredHeight());
        }
    
        public int getPreferredWidth() {
            return Display.getWidth();
        }
    
        public int getPreferredHeight() {
            int height = 6;
            int iNumFields = getFieldCount();
            for (int i = 0; i < iNumFields; i++) {
                height += getFieldHeight(getField(i));
            }
    
            return height + _heightBtmIncr + 6;
        }
    
        protected boolean keyDown( int keycode, int status ) {
            invalidate();
    
            return super.keyDown( keycode, status );
        }
    
        protected boolean navigationMovement( int dx, int dy, int status, int time ) {
            invalidate();
    
            return super.navigationMovement( dx, dy, status, time );
        }
    
        protected int moveFocus(int amount, int status, int time) {
            invalidate();
    
            return super.moveFocus(amount, status, time);
        }
    }
    

    Thank you & best regards

    pp

  • TextBoxField loop infinite sublayout

    I have two custom fields that have problems of work between them.

    One is MemoField, based on the TextBoxField in knowledge base articles. This is an edit box in a VerticalFieldManager which must only show a number of lines at a time and scroll.

    The other field is RoundedPanel that extends VerticalFieldManager and draws a box rounded on the edges.

    The two fields work very well on their own, but if I have a MemoField in a RoundedPanel and in the MemoField more than 20 lines, it goes into a loop infinite sublayout.

    Anyone know what I'm doing wrong?

    These are the classes:

    MemoField:

    public class MemoField extends VerticalFieldManager {
    
        private int _rows;
        private EditField _editField;
    
        public MemoField(int rows)
        {
    
            super(Manager.NO_VERTICAL_SCROLL);
            _rows = rows;
    
            VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL);
    
            _editField = new EditField()
            {
                public void paint(Graphics g)
                {
                    getManager().invalidate();
                    super.paint(g);
                }
            };
    
            vfm.add(_editField);
            add(vfm);
        }
    
        public void sublayout(int width, int height)
        {
    
            int w = Display.getWidth();
            int h = _editField.getFont().getHeight() * _rows;
            super.sublayout(Math.min(w, width), h);
    
            setExtent(Math.min(w, width), h);
        }
        public int getPreferredHeight()
        {
            int h = _editField.getFont().getHeight() * _rows;
            return h;
        }
    /* some get and set methods */
    }
    

    RoundedPanel:

    public class RoundedPanel extends VerticalFieldManager
    {
        public void paint(Graphics g)
        {
            int initialColor = g.getColor();
            g.setColor(Color.LIGHTGREY);
            g.fillRect(0, 0, this.getPreferredWidth(), this.getHeight());
            g.setColor(Color.WHITE);
            g.fillRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 20, 20);
            g.setColor(Color.DARKGRAY);
            g.drawRoundRect(3, 3, this.getPreferredWidth() - 6, this.getHeight() - 6, 20, 20);
            g.setColor(initialColor);
            super.paint(g);
        }
        public void sublayout(int maxWidth, int maxHeight)
        {
            super.sublayout(maxWidth, Integer.MAX_VALUE);
    
            int fieldCount = getFieldCount();
            int x = 6;
            int y = 6;
            Field child = null;
    
            for (int i = 0; i < fieldCount; i++) {
    
                child = this.getField(i);
                setPositionChild(child, x, y);
                layoutChild(child, getFieldWidth(child), Integer.MAX_VALUE);
                int childHeight = getFieldHeight(child);
                y = y + childHeight;
            }
            this.setExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
            setVirtualExtent(getPreferredWidth(), Math.max(y, getPreferredHeight()));
        }           
    
        private int getFieldWidth(Field f)
        {
            return Math.min(Math.max(Math.max(f.getContentWidth(), f.getWidth()),f.getPreferredWidth()), this.getPreferredWidth() - 12);
        }
    
        private int getFieldHeight(Field f)
        {
            int ch = f.getContentHeight();
            int h = f.getHeight();
            int ph = f.getPreferredHeight();
            return Math.max(Math.max(f.getContentHeight(), f.getHeight()),f.getPreferredHeight());
        }
    
        public int getPreferredWidth()
        {
            return Display.getWidth();
        }
    
        public int getPreferredHeight()
        {
            int height = 6;
            int iNumFields = getFieldCount();
            for (int i = 0; i < iNumFields; i++)
            {
                height += getFieldHeight(getField(i));
            }
            return height + 6;
        }
    }
    

    Thank you.

    A lot of trial and error, I seem to have fixed without really understanding why.

    If I remove the call to super.sublayout in RoundedPanel and change the width in the call to getFieldWidth (child) to maxWidth-12 layoutChild, everything seems to work properly.

    Thanks for trying to help.

  • to align the label Center field in horizontalfield Manager

    Hello world

    I have three field label inserting in horizontal field Manager, by default, it is show laft alignment.

    But I need to put all the Center horizontally.

    someone can help me.

    My code is given below

    HorizontalFieldManager curencyPrice = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER |) Manager.USE_ALL_WIDTH)
    {
    public int getPreferredHeight() {}
    Return ((int) ((30 * screenHeight) / totalHeight));
    }

    public int getPreferredWidth() {}
    Return ((int) ((200 * screenWidth) / totalWidth));
    }

    protected void sublayout (int maxWidth, maxHeight int) {}
    Super.sublayout (getPreferredWidth (),
    getPreferredHeight());
    setExtent (getPreferredWidth (), getPreferredHeight());
    }
    };

    value = new CustomLabelField_Land ("" + ht.get ("currencySymbolLeft") +"", 12389754, 25, 0,)
    // 0);
    curencyPrice.add (value);

    String s = ht.get ('price') m:System.NET.SocketAddress.ToString ();

    Value1 = new CustomLabelField_Land (s, 1521508, 25, LabelField.FIELD_HCENTER, 0);

    curencyPrice.add (value1);
    value11 = new CustomLabelField_Land ("" + ht.get ("currencySymbolRight"), 12389754, 25, 0, 0);

    curencyPrice.add (value11);

    Thanks in advance

    By default, a LabelField will only the space he needs.  And a HFM will also take only the horizontal space he needs.  You can add your HFM to a VerticalFieldManager and ensure that the HFM says FIELD_HCENTER and it focuses, as a value for money defaults across the width.

  • To implement own Custom Manager

    Hi all

    I want to set up my own Manager for my screen. Basically, I want to move over an area that is made up of field tiles bitmap either say I wish to have a manager that contains 9 tiles 200 x 200 bitmap fields; but the visible region of the Manager is also 200 x 200, so that it can display only a single tile at a time. And I want to move up, down, left and right to see the other tiles as well.

    I created a class that extends the class of Manager, have replaced the 3 as well - getPreferredWidth(), getPreferredHeight() and sublayout() methods. Then, I created an instance of this class in my class of the screen.

    What is the right way to do it? If so, I'm still not able to see anything on my screen. Could someone help me please?

    Thank you & best regards

    -Arun

    Hi all

    Thanks for your replies. I am able to do what I asked above. I set up my own ScrollListener class and managed the scroll it himself.

    Now, can someone please tell me how can I draw a shape or a text with a transparent background?

    Thank you!

    -arun

  • How to split the screen vertically?

    I want to split in the part left and right screen. The left is used to display text with RichTextField and the right side is for a button. The code is as follows:

    final RichTextField text  = new RichTextField("Hello World! To create menu items in your own application, extend this abstract class. Your subclasses must implement the Runnable  interface, which in turn supports abstract dispatching of menu actions on activation. For example.", Field.NON_FOCUSABLE);
    
    final ButtonField next = new ButtonField("Press me", ButtonField.CONSUME_CLICK);
    
    HorizontalFieldManager hrMgr = new HorizontalFieldManager();
    
    VerticalFieldManager vfMgr1 = new VerticalFieldManager(){
    
        public int getPreferredWidth() {      System.out.println("next.getWidth() = " + next.getWidth());       System.out.println("Display.getWidth() = " + Display.getWidth());     return Display.getWidth() - next.getWidth()-20;   }
    
       protected void sublayout(int maxWidth, int maxHeight) {       System.out.println("getPreferredWidth() = " + getPreferredWidth());
    
          super.sublayout(getPreferredWidth(), text.getPreferredHeight());      setExtent(getPreferredWidth(), text.getPreferredHeight());    }
    
    };vfMgr1.add(text); 
    
    VerticalFieldManager vfMgr2 = new VerticalFieldManager();vfMgr2.add(next);
    
    hrMgr.add(vfMgr1);hrMgr.add(vfMgr2);
    
    add(hrMgr);
    

    But there are 2 problems:

    1. the button cannot be displayed fully. It shrink and the text disappear.

    2. only of first line of text can be displayed and others disappear.

    Is there a way to automatically calculate the width of the buttons and height of RichTextField.

    Thank you very much!

    Replace your vfMgr1 as Manager below:

            VerticalFieldManager vfMgr1 = new VerticalFieldManager()
            {
                protected void sublayout(int width, int height)
                {
                    int w = Display.getWidth() - next.getPreferredWidth()-20;
                    Field field;
                    int fieldCount;
                    int x = 0;
                    int y = 0;
    
                    fieldCount = getFieldCount();
                    for(int i = 0; i < fieldCount; i++)
                    {
                        field = getField(i);
                        setPositionChild(field, x, y);
                        layoutChild(field, w, height);
                        y += field.getContentHeight();
                    }
                    setExtent(w, y);
                }
            };
    

    Concerning

    Bika

Maybe you are looking for

  • Type of memory PRO 4200?

    Hello. Just got hold of a 2nd hand sat 4200 laptop computer pro who retains the standard 64 MB memory in it. I want to improve it, but I don't know what kind of memory it. I saw some 256 MB PC133 SO-DIMM laptop PORTABLE MEMORY for sale close to me bu

  • Optimization of memory with several screens

    Hello I have several screens in my application and each screen has a few custom controls and bitmap images. When I move from one screen to another screen, I have more need not old screen. What is the best way to completely eliminate the permeable scr

  • GatewayEventListener writing behind the question

    HelloI'm testing a new implementation of the gemfire region in my server system, and I found some problems in a specific scenario.Ideas is the next, my server system have a bit of transaction known as region the following config:<! - the attributes o

  • Import error message

    I'm trying to import pictures from a card reader in LR 5, I get an error as they are not found. I use my Macbook Air but normally works on my iMac and it imports fine.  What is the problem?

  • Change the default e-mail - FAQ does not help

    I can't change my email address by default for the Community Site.  The FAQ is obsolete.  He referred to the former site of the community, not the new one version about a month ago.Change your E-mail addressThis page no longer applies.  The email is