ButtonField()

Hello

When I use ButtonField(), it create a button with a default size.

How can I create a little button

Thanks in advance

Hello

Look at this thread.

http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=7430&query.ID=241...

also replace getPrefferediHeight()

Tags: BlackBerry Developers

Similar Questions

  • Avoid the popup on click ButtonField

    Hey guys, rite, I've been looking for centuries now, and the problem I have is that I can't seem to stop the popup to appear, I looked through the forums and although there are a lot of things tell me how to do it, none of them seem to actually tell me how to stop the menu go up when I click on a button.

    I can get the menu to not appear, but then the button does not work.

    Its getting on my nerves now cus its pretty well the last thing I have to do on the entire application.

    Thanks in advance

    Howard

    Add CONSUME_CLICK to the style of the ButtonField.

  • 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

  • How can I reduce the size of the ButtonField

    Hello

    is it possible to reduce the size of the ButtonField. I want to make the button 50% less of the ButtonField regurla.

    is this possible? If so, how?

    can someone help me please?

    Thank you

    Maury.

    Hi mb1, thank you for your response. It worked for me. And in even, I want the text on the button must also be small. How can I do this? in fact by reducing the button, the button text is displayed as «...» "with 3 points. For example the text of the button 'click here', then after having reduced the size of the buttons, the button text is displayed as «...» ».

    I want the text of the button must be in the very small size.

    How can I achieve this. can you help me please?

    Thank you
    Maury.

  • THIS IS AN EVENT OF A BUTTONFIELD?

    btnCalc private ButtonField = new ButtonField("=")

    {

    public void run () - WARNING: Don't EVER IS USED LOCALLY

    {

    My cod is here!

    }

    };

    The btnCalc is called in the constructor by Add (btnCalc);. But, I Don t know why the vacuum run is not called!... Help please.

    setChangeListener - every field has this method.

  • Align ButtonField Center in HorizontalFieldManger when ObjectChoceField is not selected

    Hello
    I have developed a screen in which there's a topic labelField below that there is an ObjectChoiceField... My position and ObjectChoiceField do not scroll and will remain constant, under the title and ChoiceField object I have some data that must be the subject of a scroll and I could achieve this scrolling thing but my problem is that I place a button below these materials and placed this button in HorizontalFieldManager as follows

    ButtonField back;
    HorizontalFieldManager But_Back = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER);
    Back = new CustomButtonField ("Back", ButtonField.FIELD_HCENTER);
    Back.setChangeListener (this);
    But_Back.Add (back);

    The first problem: At when only the header of the loading of the page and object coice field and my left side coded hard LabelField will be present and the button below and when I select the value in the ObjectChoiceField then the values corresponding to the labelField letside will be displayed all I can attchieve using the fieldChanged but my button that is currently I am unable to put in the Center... that when the page is loaded without values are present, so the button is to the left side and when I select a value of ObjectChoiceField, then it is aligned to the Center, I want to be at the Center...
    FYI: in the order of scroll implememtn in my Constructori say

    Super (new VerticalFieldManager (), NO_VERTICAL_SCROLL);
    Here I put the code for coice position and object fields in two different HorizontalFieldManager and then announces to the screen
                 
    For the scrolling now, I create a verticalFieldManger like:
    VerticalFieldManager vor = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL |) VerticalFieldManager.VERTICAL_SCROLLBAR);
    and each variable left and right in addition to HorozontalFieldmanger
    HFM HorizontalFieldManager = new HorizontalFieldManager();
    VFM. Add (HFM);

    and at the end I say
    HorizontalFieldManager But_Back = new HorizontalFieldManager (HorizontalFieldManager.FIELD_HCENTER);
    Back = new CustomButtonField ("Back", ButtonField.FIELD_HCENTER);
    Back.setChangeListener (this);
    But_Back.Add (back);
    VFM. Add (But_Back);
    Add (VFM);

    Add Field.USE_ALL_WIDTH in your VerticalFieldManager and DrawStyle.HCENTER in your ButtonField.

    Something like:

    VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH | VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR);
    ///
    ///
    HorizontalFieldManager But_Back = new HorizontalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
    ButtonField  Back = new ButtonField("Back",DrawStyle.HCENTER);
    Back.setChangeListener(this);
    But_Back.add(Back);
    vfm.add(But_Back);
    add(vfm);
    

    Concerning

    Bika

  • Multiline ButtonField

    Is it possible to add more than one tag-line to a Buttonfield?

    Looking for some time, but was not able to find sth. similar...

    dognose

    You must override the method object and draw two or more lines of text via graphics.drawText)

    don't forget to call the super.paint (before).

  • Problem with setBorder in a buttonField custom

    Hello world

    I have a custombuttonfield and I FOCUS put border for NORMAL, ACTIVE, and DISABLED using:

    field.setBorder (ButtonField.VISUAL_STATE_NORMAL, BorderFactory.createBitmapBorder,...);

    The thing is that there is a scenario in which the button will not change until its border of development, he stays with the same active border when it is on focus. If I add just a button on the screen, it works fine, but if I add another component the focus state does not work. Is it something related to the method of paint used in the component that was added previously? The two components (button and customlabelField) are added to the manager (verticalfieldmanager) of the delegate.

    Any help would be appreciated

    Thanks and greetings

    Can you post an example that demonstrates this behavior, here or in The Issue Tracker?

    What model of Smartphone BlackBerry and the BlackBerry terminal software version you test on?  You can find this under Options, all on the BlackBerry Smartphone.

  • How to make Custom Bitmap ButtonField background transparent and not black?

    I have a buttonfield bitmaps customized using a png with transparent rounded corners. It appears as a black rectangle with the image on it. How can I make transparent blackground? I think that my problem lies in this code and I tried to use "alpha" with no results:

    Protected Sub paintBackground (Graphics Graphics) {}

    try {}
    graph.setGlobalAlpha (0);
    graph.setBackgroundColor (Color.BLACK);
    Graph.Clear ();
    }
    Finally {}
    }

    I'm sure it's a simple answer, but thanks anyway for the help!

    So I tried to do the same thing to paint override, and now the buttons are not displayed at all the haha. In any case, another programmer has helped me too and came up with the following code, it works and the problem is resolved. Thanks for your help guys, I'll put 'likes' for you. If anyone needs the code here, this is:

    SerializableAttribute public class BitmapButtonField extends {field}
    _onPicture private bitmap;
    _offPicture private bitmap;
    private int id;

    public BitmapButtonField (Bitmap onImage, Bitmap offImage) {}
    Super(Field.FOCUSABLE |) Field.FIELD_HCENTER);
    _offPicture = offImage;
    _onPicture = onImage;
    }

    {public setButtonImage Sub (onImage, offImage Bitmap Bitmap)
    _offPicture = offImage;
    _onPicture = onImage;
    }

    {} public void setButtonId (int id)
    This.ID = id;
    }

    public int getButtonId() {}
    return this.id;
    }

    public int getPreferredHeight() {}
    Return _onPicture.getHeight ();
    }

    public int getPreferredWidth() {}
    Return _onPicture.getWidth ();
    }

    protected void drawFocus (Graphics g, boolean on) {}
    }

    Protected Sub layout (int width, int height) {}
    setExtent (Math.min (width, getPreferredWidth()),
    Math.min (height, getPreferredHeight()));
    }

    Protected Sub paint (Graphics Graphics) {}
    graph.drawBitmap (0, 0, getWidth(), getHeight(), isFocus()? _onPicture: _offPicture, 0, 0);
    }

    protected boolean navigationClick (int status, int time) {}
    fieldChangeNotify (0);
    Returns true;
    }

    {} public boolean keyChar (key char, int status, int time)
    If (key == Characters.ENTER) {}
    fieldChangeNotify (0);
    Returns true;
    }
    Returns false;
    }
    }

  • FieldChangeListener on a ButtonField displays a prompt with named Application Switch and full Menu options dialog box. instead of the action set.

    Hi I use a ButtonField in my class of the screen and adds a ChangeListener and provided the measures required in

    fieldChanged(Field field, int context)
    

    method. But everytime that I click on a button, a dialog box invites you to two play as Application Switch options and full Menu.


    I think that there is a method that must be overridden to avoid this problem. I get this result when I run my app in the device with OS 5.0, but it works fine on the Simulator (7.0).

    Use ButtonField.CONSUME_CLICK as a style.

    your override of navigationclick should also work, but you would raise the event changed yourself field before return true.

  • ButtonField with background

    Hi guys,.

    I have a ButtonField customized with a background image. Here is an excerpt of my layout code

    myWidth = (int) ((double) bgOff.getWidth ());
    myHeight = (int) ((double) bgOff.getHeight ());

    setExtent (myWidth, myHeight);

    This will outline the dimensions of the ButtonField to adapt to that of the background image.

    In my painting method, I use drawBitmap to extract the background image. Here is my code.

    graphics.drawBitmap (0, 0, bgOn.getWidth (), bgOn.getHeight (), bgOn, 0, 0);

    However, this translates the background image that emerges only. I would like to have my main bitmap image on top of the background image. Centralize, if possible. Is it possible to do it this way?

    You probably forgot to put the super.paint (graphics) in your code somewhere - paint does not call as if by magic of painting of the superclass (which is what attracts this button according to focus etc..)

    A cleaner solution would be

    protected void paintBackground(Graphics graphics) {
        graphics.drawBitmap(0,0,getWidth(),getHeight(),bgOn,0,0);
    }
    

    This call is little documented, but it works.  Just look for paintBackground under the screen and you will suddenly discover that it replace another call paintBackground undocumented in the field.

    For what is centralized - you will need a few things for it.  You may be able to do this with Graphics.pushContext ().  Another approach would be like this:

    public class CenteringManager extends Manager {
      private Bitmap _bgOn;
      private int _bgWidth;
      private int _bgHeight;
      private int _width;
      private int _height;
    
      public CenteringManager(Bitmap bg) {
        _bgOn = bg;
        if (_bgOn != null) {
          _bgWidth = _bgOn.getWidth();
          _bgHeight = bgOn.getHeight();
        }
      }
    
      public int getPreferredWidth() {
        return _bgWidth;
      }
    
      public int getPreferredHeight() {
        return _bgHeight;
      }
    
      protected void sublayout(int w, int h) {
        _width = w;
        _height = h;
        if (_bgOn != null) {
          _width = Math.min(_width, _bgWidth);
          _height = Math.min(_height, _bgHeight);
        }
        if (getFieldCount() > 1) {
          throw new IllegalStateException("Cannot center more than one field.");
        }
        if (getFieldCount() > 0) { // there is one!
          Field onlyChild = getField(0);
          int childX;
          int childY;
          layoutChild(onlyChild, _width, _height);
          childX = (_width - onlyChild.getWidth()) / 2;
          if (childX < 0) {
            childX = 0;
          }
          childY = (_height - onlyChild.getHeight()) / 2;
          if (childY < 0) {
            childY = 0;
          }
          setPositionChild(onlyChild, childX, childY);
        }
        setExtent(_width, _height);
      }
    
      protected void paintBackground(Graphics g) {
        if (_bgOn != null) {
          g.drawBitmap(0,0,_width,_height,_bgOn,0,0);
        } else {
          g.clear();
        }
      }
    }
    

    You add your ButtonField to a CenteringManager instance (created in the background image you want) then you add to the screen of the Manager / which you would add normally as ButtonField.

  • Multiple ButtonFields

    Hi all!  First time display and terribly new to the whole scene of java.  Here's my situation, I had to deal at literally for days. My first try is an application of Word spelling for my little girl who is flunking spelling.

    I'm taking a Word - make a buttonfield by each letter.  When I click on the letter - it tell me what letter it is. It never returns the buttonfield.getLabel ().  Here's what I have so far.  Maybe I'm going about this all wrong.  If anyone has any advice, please let me know!

    private void createui()
        {
            try
            {
             String word = "confusion";
             for(int i = 0; i < word.length(); i++){
                    ButtonField spellbutton = new ButtonField(word.substring(i, i + 1),ButtonField.CONSUME_CLICK);
                    spellbutton.setChangeListener(this);
                    add(spellbutton);
             }        
    
            }
            catch (Exception e)
            {
                System.out.println("Failed to create user interface components");
            }
        }
    
        public void fieldChanged(Field f, int context)
        {
    
                    Dialog.alert(spellbutton.getLabel());
    
            }
    

    spellButton.getLabel () does not contain anything relevant to the domain object is passed to the listener.

    The 'Field' parameter contains a reference to the button the user has clicked.

    Your fieldChanged() should probably look like this:

    ButtonField button = field (ButtonField);

    Dialog.Alert (Button.getLabel ());

  • put image in buttonField?

    Hello, I would like to know how can I put an image in a buttonField, first is it possible?

    It's my code. It can help you

    package maz.fields.button;
    
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.Graphics;
    
    public class ImageButtonField extends Field{
    
        Bitmap _unfocus,_focus,_unfocus_selected,_focus_selected;
        boolean isSelect = false;
    
        public ImageButtonField(Bitmap unfocus, Bitmap focus,long style) {
            // TODO Auto-generated constructor stub
            super(style);
            _unfocus = unfocus;
            _focus = focus;
        }
    
        public ImageButtonField(Bitmap unfocus, Bitmap focus, Bitmap selected ,long style) {
            // TODO Auto-generated constructor stub
            super(style);
            _unfocus = unfocus;
            _focus = focus;
            _unfocus_selected = selected;
        }
    
        public ImageButtonField(Bitmap unfocus, Bitmap focus, Bitmap unfocus_selected, Bitmap focus_selected ,long style) {
            // TODO Auto-generated constructor stub
            super(style);
            _unfocus = unfocus;
            _focus = focus;
            _unfocus_selected = unfocus_selected;
            _focus_selected = focus_selected;
        }
    
        public void set_unfocus(Bitmap _unfocus) {
            this._unfocus = _unfocus;
        }
    
        public void set_focus(Bitmap _focus) {
            this._focus = _focus;
        }
    
        public int retriveHeight(){
            return _unfocus.getHeight();
        }
    
        public int retriveWidth(){
            return _unfocus.getWidth();
        }
    
        public void setSelect(boolean _isSelect){
            isSelect = _isSelect;
            invalidate();
        }
    
        public boolean getSelect(){
            return isSelect;
        }
    
        protected void paint(Graphics graphics) {
            // TODO Auto-generated method stub
                if(!isFocus()){
                    if(isSelect){
                        graphics.drawBitmap(0, 0, _unfocus_selected.getWidth(), _unfocus_selected.getHeight(), _unfocus_selected, 0, 0);
                    }else{
                        graphics.drawBitmap(0, 0, _unfocus.getWidth(), _unfocus.getHeight(), _unfocus, 0, 0);
                    }
                }else {
                    if(_focus_selected!=null){
                        if(isSelect){
                            graphics.drawBitmap(0, 0, _focus_selected.getWidth(), _focus_selected.getHeight(), _focus_selected, 0, 0);
                        }else{
                            graphics.drawBitmap(0, 0, _focus.getWidth(), _focus.getHeight(), _focus, 0, 0);
                        }
                    }else{
                        graphics.drawBitmap(0, 0, _focus.getWidth(), _focus.getHeight(), _focus, 0, 0);
                    }
                }
        }
    
        public boolean isFocusable() {
            return true;
        }
    
        protected void drawFocus(Graphics graphics, boolean on) {
        }
    
        protected void onFocus(int direction) {
            super.onFocus(direction);
            invalidate();
        }
    
        protected void onUnfocus() {
            super.onUnfocus();
            invalidate();
        }
    
        protected void layout(int width, int height) {
            setExtent(_focus.getWidth(), _focus.getHeight());
        }
    }
    

    MAZ

  • How to select and change the LabelFields / ButtonFields table 2D

    Hi everyone, I'm new here and I'm new to the blackberry development.

    For a project student I'm working, I have a table 2D-ButtonFields, (I can change LabelFields if it's easier) which I use to create a Sudoku grid.

    I understand that this is really basic but I want the user to simply scroll the table 2D to a particular cell, and be able to type in a number on the keyboard instantly change the label of the ButtonField or LabelField, IE their assumption of Sudoku.

    I have really problems that I'm not familiar with how blackberry accepts user input and how it can be used with the setText method.

    So, essentially, I would like some sort of way to determine the currently selected cell (without is activated) and then for this selected cell so that the setText() method applied

    Can someone help me? I can post a code if it helps but I'm not sure it will as you al will understand how basic it is.

    Thank you in advance and I hope I can return the favor as soon as

    You can use a focuschangelistener to be aware of policy changes. or call the getLeafFieldWithFocus() to retrieve the current field.

    You can't make buttonfields editable, but you can read user input and treat it.

    for sudoku you need only numbers, you can use the keyChar method to read the characters.

    Check if your target field is one of your buttons. Check to see if the tank is entered or Louis tank (Keypad.getAltedChar) is a number (Characters.isDigit).

    You can call setText on of the buttonfield.

  • FixedWidth buttonField cannot Center the text


    Hi macdan,.

    I think that in such cases it is advisable to extend the scope rather than ButtonField.

    Try this CustomButtonField. Hope that it will achieve your problem.

    import net.rim.device.api.ui.Field;
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.system.Bitmap;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.XYRect;
    import net.rim.device.api.ui.XYPoint;
    import net.rim.device.api.system.Characters;
    
    public class CustomButtonField extends Field
    {
        private String label;
        private int labelLength;
        private int width;
        private int height;
        private int alignment;
        private XYPoint labelTopLeftPoint;
        private boolean isFocusable;
    
        /**
         * Margin for the button
         */
        private final static int DEFAULT_LEFT_MARGIN = 1;
        private final static int DEFAULT_RIGHT_MARGIN = 1;
        private final static int DEFAULT_TOP_MARGIN = 4;
        private final static int DEFAULT_BOTTOM_MARGIN = 4;
    
        /**
         * Padding for the button
         */
        private final static int DEFAULT_LEFT_PADDING = 5;
        private final static int DEFAULT_RIGHT_PADDING = 5;
        private final static int DEFAULT_TOP_PADDING = 4;
        private final static int DEFAULT_BOTTOM_PADDING = 4;
    
        /**
         * Margins around the text box
         */
        private int leftMargin = DEFAULT_LEFT_MARGIN;
        private int rightMargin = DEFAULT_RIGHT_MARGIN;
        private int topMargin = DEFAULT_TOP_MARGIN;
        private int bottomMargin = DEFAULT_BOTTOM_MARGIN;
    
        /**
         * Padding around the text box
         */
        private int leftPadding = DEFAULT_LEFT_PADDING;
        private int rightPadding = DEFAULT_RIGHT_PADDING;
        private int topPadding = DEFAULT_TOP_PADDING;
        private int bottomPadding = DEFAULT_BOTTOM_PADDING;
    
        /**
         * Alignment
         */
         public final static int ALIGNMENT_LEFT = 0x00000001;
         public final static int ALIGNMENT_RIGHT = 0x00000002;
         public final static int ALIGNMENT_TOP = 0x00000004;
         public final static int ALIGNMENT_BOTTOM = 0x00000008;
         public final static int ALIGNMENT_CENTER = 0x00000010;
    
        public final static int DEFAULT_BACKGROUND_COLOR_NORMAL = 0x00ffffff;
        public final static int DEFAULT_BACKGROUND_COLOR_ON_FOCUS = 0x009c0000;
        private int backgroundColorNormal = DEFAULT_BACKGROUND_COLOR_NORMAL;
        private int backgroundColorOnFocus = DEFAULT_BACKGROUND_COLOR_ON_FOCUS;
    
       public final static int ALIGNMENT_DEFAULT = ALIGNMENT_LEFT | ALIGNMENT_TOP;
    
        public CustomButtonField(final String label)
        {
            this(label, 0);
        }
    
        public CustomButtonField(final String label, int width)
        {
            super();
    
            this.label = (label == null) ? "" : label;       
    
            this.isFocusable = true;
            Font font = getFont();
    
            labelLength = font.getAdvance(this.label);
    
            this.width = (width != 0) ? width : (labelLength + leftMargin + leftPadding + rightPadding + rightMargin);
            this.height = font.getHeight() + topMargin + topPadding + bottomPadding + bottomMargin;
    
            labelTopLeftPoint = new XYPoint();
    
            setAlignment(ALIGNMENT_DEFAULT);
        }
    
        public void setWidth(int width)
        {
            int displayWidth = Display.getWidth();
    
            if (width > 0 && width <= displayWidth)
            {
                this.width = width;
                adjustAlignment();
            }
        }    
    
        public void setWidth(String refStr)
        {
            this.labelLength = getFont().getAdvance(refStr);
            int tempWidth = leftMargin + leftPadding +  labelLength + rightPadding + rightMargin;
    
            setWidth(tempWidth);
        }
    
        public void setHeight(int height)
        {
            this.height = height;
        }
    
        public void setSize(int width, int height)
        {
            setWidth(width);
            setHeight(height);
        }    
    
        public void setAlignment(int alignment)
        {
            if ((alignment & ALIGNMENT_CENTER) != 0)
            {
                this.alignment = alignment;
            }
            else
            {
                this.alignment = 0;
    
                if ((alignment & ALIGNMENT_RIGHT) != 0)
                {
                    this.alignment |= ALIGNMENT_RIGHT;
                }
                else
                {
                    this.alignment |= ALIGNMENT_LEFT;
                }
    
                // Vertical alignment
                if ((alignment & ALIGNMENT_BOTTOM) != 0)
                {
                    this.alignment |= ALIGNMENT_BOTTOM;
                }
                else
                {
                    this.alignment |= ALIGNMENT_TOP;
                }
            }
            adjustAlignment();
        }
    
        private void adjustAlignment()
        {
            int leftBlankSpace = leftMargin + leftPadding;
            int rightBlankSpace = rightPadding + rightMargin;
    
            int topBlankSpace = topMargin + topPadding;
            int bottomBlankSpace = bottomMargin + bottomPadding;
    
            if ((alignment & ALIGNMENT_CENTER) != 0)
            {
                int emptySpace = width - (leftBlankSpace + labelLength + rightBlankSpace);
    
                labelTopLeftPoint.y = topBlankSpace;
                labelTopLeftPoint.x = leftBlankSpace + emptySpace/2;
            }
            else
            {
                // Horizontal alignment
                if ((alignment & ALIGNMENT_LEFT) != 0)
                {
                    labelTopLeftPoint.x = leftBlankSpace;
                }
                else if ((alignment & ALIGNMENT_RIGHT) != 0)
                {
                    labelTopLeftPoint.x = width - (labelLength + rightBlankSpace);
                }
                labelTopLeftPoint.y = topBlankSpace;
            }
        }
    
        public String getText()
        {
            return label;
        }
    
        public int getButtonWidth()
        {
            return width;
        }
    
        public void setLeftMargin(int leftMargin)
        {
            if (leftMargin >= 0)
            {
                this.width -= this.leftMargin;
                this.leftMargin = leftMargin;
                this.width += this.leftMargin;
    
                adjustAlignment();
            }
        }
    
        public void setRightMargin(int rightMargin)
        {
            if (rightMargin >= 0)
            {
                this.width -= this.rightMargin;
                this.rightMargin = rightMargin;
                this.width += this.rightMargin;
    
                adjustAlignment();
            }
        }
    
        public void setTopMargin(int topMargin)
        {
            if (topMargin >= 0)
            {
                this.height -= this.topMargin;
                this.topMargin = topMargin;
                this.height += this.topMargin;
                adjustAlignment();
            }
        }
    
        public void setBottomMargin(int bottomMargin)
        {
            if (bottomMargin >= 0)
            {
                this.height -= this.bottomMargin;
                this.bottomMargin = bottomMargin;
                this.height -= this.bottomMargin;
    
                adjustAlignment();
            }
        }
    
        public void setMargin(int topMargin, int rightMargin, int bottomMargin,int leftMargin)
        {
            setLeftMargin(leftMargin);
            setRightMargin(rightMargin);
            setTopMargin(topMargin);
            setBottomMargin(bottomMargin);
        }
    
        public void setFocusable(boolean isFocusable)
        {
            this.isFocusable = isFocusable;
        }
    
        public int getPreferredWidth()
        {
            return width;
        }
    
        public int getPreferredHeight()
        {
            return height;
        }
    
        protected void layout(int width, int height)
        {
            setExtent(Math.min(getPreferredWidth(), width), Math.min(getPreferredHeight(), height));
        }
    
        protected void paint(Graphics graphics)
        {
            int w = width - (leftMargin + rightMargin);
            int h = height - (topMargin + bottomMargin);        
    
            if(isFocus() == false)
            {
                graphics.setColor(backgroundColorNormal);
                graphics.fillRoundRect(leftMargin, topMargin, w, h, 6, 6);
                graphics.setColor(0x00394142);
                graphics.drawRoundRect(leftMargin, topMargin, w, h, 6, 6);
                graphics.drawText(label,  labelTopLeftPoint.x, labelTopLeftPoint.y);
            }
            else
            {
                graphics.setColor(backgroundColorOnFocus);
                graphics.fillRoundRect(leftMargin, topMargin, w, h, 6, 6);
                graphics.drawRoundRect(leftMargin, topMargin, w, h, 6, 6);
    
                graphics.setColor(0x00ffffff);
                graphics.drawText(label,  labelTopLeftPoint.x, labelTopLeftPoint.y);
            }
        }
    
        public boolean isFocusable()
        {
            return isFocusable;
        }
    
        public void getFocusRect(XYRect rect)
        {
            rect.set(leftMargin, topMargin, width - (leftMargin + rightMargin), height - (topMargin + bottomMargin));
        }
    
        protected void drawFocus(Graphics graphics, boolean on)
        {
            invalidate();
        }
    
        public boolean keyChar(char key, int status, int time)
        {
            if (key == Characters.ENTER)
            {
                fieldChangeNotify(0);
                return true;
            }
    
            return false;
        }
    
        protected boolean navigationClick(int status, int time)
        {
            fieldChangeNotify(0);
            return true;
        }
    }
    

    And from your screen main alignment of the button text.

    //CustomButtonField button1 = new CustomButtonField("Button1");
    CustomButtonField button1 = new CustomButtonField("Button1", Display.getWidth() / 2);
    button1.setAlignment(CustomButtonField.ALIGNMENT_CENTER);
    

    Concerning

    Bika

  • regarding buttonField

    Hello

    I had added the

    ButtonField mySubmitButton = new ButtonField ("Accept");

    Add (mySubmitButton);

    Accept button appears on the screen.

    So how do the codes by pressing the button I accept.

    I want to make is that, when the user press the button accept, is true of the other class and msg comes "installation of an application.

    II has the study which FieldChangeListener is used, but no not a single idea to use it for acceptance of the buttonField

    Thank you and best regards

    Antoine SIngh

    You must create a class that extends to fieldChangelistener, then for your button to accept, you can use following code

    mySubmitButton.setChangeListener();
    

    in your fieldChanged method, you will need to write code that illustrates the other screen.

Maybe you are looking for