Width LabelField

How can I set the default width of a LabelField.  Currently if I draw a border around each LabelField with one character in each box, the field that holds a 'I' is narrower than a field that contains a 'W '.  How can I do to make each LabelField has the same width?

Thank you!

LabelField _buttonfield_highscore = newLabelField ("Hello") {public int getPreferredWidth() {return 200 ;} protected Sub layout (int maxWidth, maxHeight int) {super.layout (getPreferredWidth(), maxHeight) ;}};}}}

Tags: BlackBerry Developers

Similar Questions

  • Maximum width LabelField

    Hi, I'm sure that many applications that have lists have successfully done a certain way or another but I can't figure out how!

    The problem is, I listfield with labelfields in them and I want them to display the content in a single line. So if the text in the labelfield overflows, I won't display on multiple lines, but intersect at the end and be replaced by «...» »

    I considered the max character length in the labelfield but this would produce a contradictory result because each alphabet have different widths.

    I do not know how to approach this problem, is there a api for this kind of situation? Auto replace the remaining characters by «...» » ?

    There is a model for this; LabelField.ELLIPSIS

    (if I have the correct spelling)

    See the javadocs.

  • labelfield word wrapping

    Hello

    I wanted to design a screen in which a text (paragraph) will be centered aligned with some space left as left right side.

    right now use width LabelField (Display.getWidth () - 50), but am not able to do it centered aligned with little space left behind the two.

    I also used LAbelField.HCENTER, but not so useful

    the text int the wording field must be encapsulated as width decreases.

    does anyone have the knowledge about it.

    Thanks in advance

    Here's an example how you can wrap the line in labelfield

    your labelField has a width (Display.getWidth () - 50)

    LabelField temp_label = new LabelField("", Field.USE_ALL_WIDTH | DrawStyle.LEFT) {
        public int getPreferredWidth() {
            return Display.getWidth() - 50;
        } 
    
        protected void layout(int maxWidth,int maxHeight) {
            super.layout(getPreferredWidth(),maxHeight);
            setExtent(getPreferredWidth(), getHeight());
        }
    };
    temp_label.setText("This is a long statement.");
    

    try this out. It will work

    Thank you.

  • How to create a labelfield with fixed width and dynamic height?

    I got this question in fact for a long time and I have not found answer in this forum so far.

    As we know, we can use:

    public int getPreferredWidth()
    {
        return fixedSize;
    }
    
    protected void layout(int width,int height)
    {
        super.layout(getPreferredWidth(), getPreferredHeight());
        super.setExtent(getPreferredWidth(), getPreferredHeight());
    }
    

    to set the width fixed in a field, but if the text is too long and should be multiline, this will bring problem, getPreferredHeight() only returns the preferred height, which is actually not the actual height, so the text will be hashed.

    So what should this setting? height?

    super.setExtent(getPreferredWidth(), height));
    

    No.... the height value is too large.

    So, how can we set this parameter to make this labelfield looks perfectly.

    Any idea?

    A search on the web is expected to increase a lot of examples of functions in Java text wrapping. Especially for BlackBerry, you can use Font.getAdvance (String text, int start, int len) to measure the width of a text segment without the expense of creation of substrings.

    The basic logic is to analyze the text character by character. If the "\n" character, force a line break. If the character is a space, then it is a line break candidate; Check if the line so far is set. If so, then move the candidate to that character end and continue; If this is not the case, go back to the previous candidate break and put an end to the line right there. The loop is initialized so that there is always at least one character on the line. The process ends when you run out of text. Details (including dealing with empty text, several spaces, etc.) are kept as an exercise for the reader, or search the Web well.

    I wouldn't worry efficiency. Put on the page of the field is not all that often, and when it's done, there's no escape from the need to make the work of packaging line at some point before the text is rendered on the screen. One way to avoid unnecessarily repeating work is to memoize the function of packaging line: wrapped lines and the width of the film cache and reuse them as needed. The cache is marked invalid if changes to text or the current width and the width of the film cached differ.

  • Prediction of the LabelField width front layout of 2 pixels


    I solved it myself. Here's the fix

    public class BBFocusPadding {}

    public static int padding = 0;

    }

  • LabelField, 4.6 vs.5.0, is this a bug?

    Ok

    Here are simple custom LabelField:

    public class BitmapButtonField extends LabelField {
    
        private Bitmap BmOnFocus;
        private Bitmap BmOffFocus;
    
        public BitmapButtonField(long _style,                              Bitmap _onFocus,                              Bitmap _offFocus) {
            super("", _style);
            BmOnFocus = _onFocus;
            BmOffFocus = _offFocus;
        }
    
        public int getPreferredHeight() {
            return BmOnFocus.getHeight();
        }
        public int getPreferredWidth() {
            return BmOnFocus.getWidth();
        }
        protected void layout(int width, int height) {
            int h = getPreferredHeight();
            int w = getPreferredWidth();
            super.layout(w, h);
            setExtent(w, h);
        }
    ....
    };
    

    The 'problem' with this code is that it works OK when compiled and run under OS 5.0

    and gives error when compiled and running on 4.6.

    The error is that BmOnFocus has the value null when getPreferredWidth() is called!

    The use of this field as usual

    BitmapButtonField bfGame = new BitmapButtonField(Field.FOCUSABLE, imgGame, imgGameNS);
    add(bfGame);
    

    Looks like the 'bad' superdeal ("", _style ") name () of layoutand of course by this time bitmaps are not yet defined.

    But why it works on 5.0?

    Ok

    workaround was quite simple - I commented getPreferredWidth () /Height () methods

    and changed layout() for:

        protected void layout(int width, int height) {
            int h = BmOnFocus.getHeight();
            int w = BmOnFocus.getWidth();
            super.layout(w, h);
            setExtent(w, h);
        }
    

    In my case it was OK.

  • HorizontalFieldManager custom: cannot field presentation, insufficient height or width

    I have two fields to label that I need for available side by side in a manager of horizontal field. When ran, the outputs of the Console: "cannot the field presentation, insufficient height or width.

    When I insert a breakpoint, the values are:

    • width = 480
    • height = 1073741823

    Why is the value of great height? (Oh yes, the virtual height.)

    What is the right way to calculate the height - just use the height field's favorite?

    LabelField lf = new LabelField("Flavor");
    LabelField olf = new LabelField("Order");
    
    HorizontalFieldManager hfm = new HorizontalFieldManager(
            Manager.NO_HORIZONTAL_SCROLL
                    | Manager.NO_HORIZONTAL_SCROLLBAR) {
    
            protected void sublayout(int width,
                int height) {
            Field field;
            int numberOfFields = getFieldCount();
            int x = 0;
            int y = 0;
    
            for (int i = 0; i < numberOfFields; i++) {
                field = getField(i);
                setPositionChild(field, x, y);
                layoutChild(field, width,
                        height);
                y += 10;
            }
    
            int myWidth = Math.min(width,
                    getPreferredWidth());
            int myHeight = height;
    
            super.sublayout(myWidth, myHeight);
    
            setExtent(myWidth, myHeight);
        }
    
        public int getPreferredWidth() {
            return getScreen().getWidth();
        }
    };
    
    hfm.add(olf);
    hfm.add(lf);
    

    You all that hard work the fields chickens and then try to destroy with super.sublayout () call. I'm sure that's what throws the exception. Check your myWidth and myHeight before the call to super.sublayout (). You might find that getPreferredWidth() returns to zero.

    I don't know why you would want to increase the parameter y in a horizontal field in any event handler. If anything, set x and not just randomly, by 10, but by the field.getWidth (). But it's logical that if you extend the Manager and remove super.sublayout call.

    More important still, you can get what you want much easier to not the substitution of all sublayouts and instead use setMargin on your domains.

  • LabelFields in the pop-up screen centering

    I am centering a PopUp screen and add a few LabelFields which must be centered too. I put the position of the Popup manually, but the LabelFields aren't always align properly... What have I done wrong?

    The PopupScreen position which focuses more or less now:

    private final static int _X = (Display.getWidth() - 510);
    private final static int _Y = (Display.getHeight() - _Height) >> 1;
    
    public void sublayout(int width, int height) {
            super.sublayout(getPreferredWidth(), Integer.MAX_VALUE);
            setExtent(getPreferredWidth(), getPreferredHeight());
            setPosition(_X, _Y);
        }
    

    These are the LabelFields thereon that are even more on the left side:

    LabelField title = new LabelField("UI Test App",
                    Field.FIELD_HCENTER);
    LabelField version = new LabelField("Version X.Y",
                    LabelField.FIELD_HCENTER);
    
    add(title);
    add(version);
    

    "It seems that the separatorField has a standard in a popup length if you don't customize it?

    Sort of.  In fact, the SeparatorField wants to put in a separator that is as wide as Manager it is in. so, indeed, it will force the Manager to use the full width that it is given.

    One way round this is to limit width is given by the Manager. Here's some code to show how do.  See screen capture for the result.

       public InfoScreen() {
            super(new VerticalFieldManager() {
                public void sublayout(int width, int height) {
                    super.sublayout(Math.min(width, Display.getWidth()/2), height);
                }
            });
            LabelField title = new LabelField("UI Test App", Field.FIELD_HCENTER);
            LabelField version = new LabelField("Version X.Y",
                    LabelField.FIELD_HCENTER);
            ButtonField closeBtn = new ButtonField("Close", ButtonField.FIELD_HCENTER);
            add(title);
            add(version);
            add(new SeparatorField());
            add(closeBtn);
        }
    

    There are other options, for example, you can use the page layout in the SeparatorField to restruct its width.  Then the Director would not forced to use any of its width by the SeparatorField.  The best option will depend on exactly what you are trying to reach and what other restrictions you have.

  • How to show the number n of labelfields in a HFM without roller horizontal sc

    Hi all

    I want to show n number of labels without scrolling in a HFM areas, how?

    The suggestion above reduces to a minimum the width given to each LabelField so that they fit.  If you want just the overlow when the screen width has been reached, try FlowFieldManager.

  • Adding a LabelField with implementation in custom page &amp; paint freezes App.

    It's the absolute weirdest thing, I met so far. After error for about an hour, I narrowed down it to the following instructions.

    I have a class that extends the screen, I add the following to the constructor of the class and the App freezes each and ever time. The area of the label takes the string value of the variable title twice to create a white color with a slight black shadow text.

    That's it... nothing else.

    However, it freezes the App.

    There is something blatantly obvious that I'm missing?

    LabelField t = new LabelField() {
        int xy = 14;
    
        protected void layout(int width, int height) {
            setExtent(width, getPreferredHeight() + xy);
        }
    
        protected void paint(Graphics g) {
            g.setColor(Color.BLACK);
            g.drawText(title, xy, xy - 3);
            g.setColor(Color.WHITE);
            g.drawText(sportTitle, xy, xy - 2);
            invalidate();
            super.paint(g);
        }
    };
    
    Font font = Font.getDefault().derive(Font.BOLD | Font.SANS_SERIF_STYLE, 8, Ui.UNITS_pt);
    t.setFont(font);
    add(t);
    

    My first instinct is to delete your method invalidate() object.

    I'm sure that it's more than a typo in your case; in general, however, it is an extremely bad approach, aggravated by the frequency with which all kinds of 'gurus' use in their articles and responses. The endless loop it creates is 'soft', which means useful work will have a chance to be, but you'll be safer without him.

    However, there are other problems in your code:

    Your code layout() is not enough. When you extend a real (not abstract) field, you really want to use super.layout there is somewhere - if your super.paint won't know where to paint! Either extend the field and make all paint yourself (and then you could limit the layout to the right setExtent - but you really want to do more there, calculation of widths, positions, etc.), or call the super.layout somewhere.

    Your exersizes with two calls drawText will be spoiled by the later super.paint call. First call super.paint, then paint over it (in general, you should be careful with this approach, but here, it makes sense).

  • Clickable labelfield

    Is there a way to create a clickable labelfield? Or would I need to use a listfield even when there are only two entries?

    I would like a clickable label that covers the width of the container full, despite a short text.

    Use a movement Manager

    {Label
    gestureHandlers:]
    {TapHandler}
    onTapped: dowhatever
    }
    ]
    }

  • LabelField with background bitmap file

    I would like to show a LabelField with a background as (01.gif, the yellow circle is the bmp and the labelField is '1'). My code is as follows:

    final Bitmap bmp = Bitmap.getBitmapResource("img/circulo_numero.png");
    LabelField lblPaso = new LabelField("1", Field.FIELD_RIGHT) {
        protected void paintBackground(Graphics g) {
            g.drawBitmap(0, 0, bmp.getWidth(), bmp.getHeight(), bmp, 0, 0);
            super.paint(g);
        }
    
        public int getPreferredWidth() {
            return  bmp.getWidth();
        }
    
        public int getPreferredHeight() {
            return bmp.getHeight();
        }
    
        protected void layout(int width, int height) {
            super.layout(width, height);
            setExtent(Math.min(width, bmp.getWidth()), Math.min(height, bmp.getHeight()));
        }
    };
    

    However, I got results as indicated in 02.gif...

    How can I solve this problem?

    TIA,

    Yamil

    Sorry, I'm not your post earlier. In any case, here is an explanation:

    Your number 1 is painted where LabelField wants to paint. Unfortunately, you don't try to control where he went to paint it or where it will be placed, by the way. Fortunately, there is an old creation of mine tailor-made for you. Here it is:

    Re: ButtonField with background

    Simply create a CenteringManager with the bitmap you want to use as a background, add your LabelField and enjoy.

  • How can I set the width of the part of the label of an edit field?

    Anyone know how I can configure the width of the part of the label of an edit field?  that is, I want to have my line to edit until a fixed width field labels.

    It is not possible to set the width of the part of the label of an editfield.

    In this case, you can use a LabelField with fixed width (the substitution of layout() method) and an EditField and add then both a HorizontalFieldManager.

    Concerning

    Bika

  • Question of the development of EditField and LabelField in HorizontalFieldManager

    I actually want a custom editfield (a label with a textbox), when he got focus on this textbox draws a border of climax, and I want the label got the same effect, however, I drew a border outside the text easily because of the text box could receive focus , here is my code:

    public class MyTextField extends EditField
    {
        public MyTextField()
        {
            super();
        }
    
        public void layout(int width, int height)
        {
            super.layout(width, height);
        }
    
        protected void paint(Graphics g)
        {
            if(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))
            {
                setBorder(BorderFactory.createRoundedBorder(new XYEdges(6, 6, 6, 6), 0x186DEF, Border.STYLE_SOLID));
            }else{
                setBorder(BorderFactory.createRoundedBorder(new XYEdges(6, 6, 6, 6), Color.GRAY, Border.STYLE_SOLID));
            }
    
            super.paint(g);
         }
    }
    

    And I use this code to show in screen

           HorizontalFieldManager hfm=new HorizontalFieldManager();
            LabelField label=new LabelField("something");
            MyTextField text=new MyTextField();
    
            hfm.add(label);
            hfm.add(text);
            add(hfm);
    

    Is there a way to implement that when the textbox has got the update at the same time also changed the color of the text of the label.

    set a Boolean flag that you record in paint, set it on the ground (from outside) and invalid call to redraw.

  • How to make a labelfield right aligned text

    I want to make my label text aligned to right field in then the screen

    LabelField content = new LabelField(description,LabelField.FOCUSABLE|USE_ALL_WIDTH|FIELD_RIGHT)
    

    This labelfield, I add to an optimization of internal resources

    VerticalFieldManager vfm = new VerticalFieldManager (
                    VerticalFieldManager .VERTICAL_SCROLL
                            | VerticalFieldManager .FOCUSABLE) {
                protected void sublayout(int width, int height) {
    
                    super.sublayout(Display.getWidth() - 20, height);
                    setExtent(Display.getWidth() - 20, 33);
                }
            };
    

    This optimization of internal resources, I add to main vfm called external resources management and in defining its position

    layoutChild(vfm, maxWidth, maxHeight);
                        setPositionChild(vfm,290, 123);
    

    My screen is 320 x 240

    But the text goes out of the screen. Help, please

    Forget all the positioning in the Manager and try this:

    Content LabelField = new LabelField (description, LabelField.FOCUSABLE |) DRAWSTYLE. (RIGHT);

    Announcing this to a VerticalFieldManager or directly to your screen and I think this should work for you.

    If this is not the case, let know us and we can look at the positioning of the field.

    As a side note, it seems doubtful:

    protected void sublayout (int width, int height) {}
    Super.sublayout (Display.GetWidth () - 20, height);
    setExtent (Display.getWidth () - 20: 33);
    }

    What you trying to do?  Why is the 33 important?

Maybe you are looking for

  • Understand what I would be buying

    I downloaded Toshiba BT Stack to test with a USB dongle not - Toshiba a Win7Pro, 64-bit. First impressions are very good, and I plan to buy the battery. It is not clear to me, however, exactly what I would like to buy. By clicking on the product lice

  • 50-200 F3. 5 - 4.5 (58) will be this lens created in 1987 working on a camera Eos XS?

    50-200 F3. 5 - 4.5 (58) will be this lens created in 1987 working on a camera Eos XS?

  • AMD Radeon 7420G

    Help me please with driver for AMD Radeon 7420 G. I was installed for 7 x series driver and I have lag in simple games like counter-strike 1.6. I turn me off my second video card (512 MB), now I have switchable graphics.

  • Get use of the resources of all virtual machines in a cluster

    Hello I have developed a measure of capacity management report that collects all the use of the resources of the virtual machines in a datacenter. The function that collects it looks like this: def hostMemoryConsumed =] def memoryConsumed = 0.0f def

  • DMVPN is not tipping as expected

    Hi all I tested on a laboratory based on http://www.Cisco.com/en/us/Tech/tk583/TK372/technologies_white_paper09186a008018983e.shtml#dualhubdual In my lab, I have 2hubs of installation and 1 backup server I did everything according to the document fro