How to set a width of ObjectChoiceField?

Hello

can someone tell me how I can set a width of objectchoicefield.

Suppose that there are two values in objectchoicefield.

'abc '.

"abcdefg".

now I want the width should be equal to the string max.

When I select abc the objectchoicefield become smaller compared to the "abcdefg".

now I want the width should be equal to the string max.

Hello

I think you should write an overring of the custom ObjectChoiceField class by provision of overring, paint, drawfocus etc needs to satisfy you.

OK, here's one of my custom ObjectChoiceField class. Copy pasted from one of my old code.

I think that playing around with the code you will should be able to do like yours.

import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.Graphics;
import java.lang.String;
import net.rim.device.api.ui.XYRect;
import net.rim.device.api.ui.Font;
import net.rim.device.api.system.Bitmap;

public class CustomChoiceField extends ObjectChoiceField
{    

    /** Constants for the horizontal text alignment */
    public static final int TEXT_HALINGMENT_LEFT = 0;
    public static final int TEXT_HALINGMENT_CENTER = 1;        

    /** Array of choices */
    String[] m_Choices;    

    /** Left margin of the field */
    private int m_MarginLeft = 1;    

    /** Right margin of the field */
    private int m_MarginRight = 1;    

    /** Top margin of the field */
    private int m_PaddingTop = 5;    

    /** Top margin of the field */
    private int m_PaddingBottom = 5;        

       /** Top margin of the field */
    private int m_MarginTop = 5;    

    /** Top margin of the field */
    private int m_MarginBottom = 5;       

    /** Right margin of the text in the selectbox */
    private int m_TextMarginRight = 5;    

    /** Left margin of the text in the selectbox */
    private int m_TextMarginLeft = 5;    

    /** Horizonta text alingment */
    private int m_HTextAlignment = TEXT_HALINGMENT_CENTER;    

    /** Width of the chpice box */
    private int m_ChoiceFieldWidth;    

    /** Height of the field */
    private int m_Height;    

    /** Determones is field focused */
    private boolean m_isFocused = false;    

    /** Width of thr DropDown arrow */
    private int m_DropDownArrowWidth;        

    /** Field default color */
    private int m_DefBgColor = 0xffffff;    

    /** Field text default color */
    private int m_DefTextColor = 0;    

    /** Field color when it is focused */
    private int m_FocusedBgColor = 0xf6921e;    

    /** Field text color when it is focused */
    private int m_FocusedTextColor = 0;        

    /**     * Constructor. The width of choice box became as big as
    * maximum length of choice strings + text marfins + derop-down arrow width.
    * *      * @param String - label of the field
    * * @param String[] - field choices
    * */
    public CustomChoiceField(String label, String[] choices)
    {
        super(label, choices);
        m_Choices = choices;        

        //dimensions of selectable field
        Font currFont = getFont();
        m_DropDownArrowWidth = m_Height = currFont.getHeight();
        m_ChoiceFieldWidth = currFont.getAdvance(choices[0]);
        for(int i = 1; i < choices.length; i++)
        {
            if(m_ChoiceFieldWidth < currFont.getAdvance(choices[i]))
                m_ChoiceFieldWidth = currFont.getAdvance(choices[i]);
        }
        m_ChoiceFieldWidth += m_TextMarginLeft + m_TextMarginRight + m_DropDownArrowWidth;
    }        

    /**     * Constructor. The width of choice box became as big as
    * maximum length of choice strings + text marfins + derop-down arrow width.
    * *
    * * @param String - label of the field
    * * @param String[] - field choices
    * * @param int - initial choice index
    * */
    public CustomChoiceField(String label, String[] choices, int initialIndex)
    {
        super(label, choices, initialIndex);
        m_Choices = choices;        

        //dimensions of selectable field
        Font currFont = getFont();
        m_DropDownArrowWidth = m_Height = currFont.getHeight();
        m_ChoiceFieldWidth = currFont.getAdvance(choices[0]);
        for(int i = 1; i < choices.length; i++)
        {
            if(m_ChoiceFieldWidth < currFont.getAdvance(choices[i]))
                m_ChoiceFieldWidth = currFont.getAdvance(choices[i]);
        }
        m_ChoiceFieldWidth += m_TextMarginLeft + m_TextMarginRight + m_DropDownArrowWidth;
    }        

    /**
    * Constructor. The width of choice box became as big as
    * * maximum length of choice strings + text marfins + derop-down arrow width.
    * *
    * * @param String - label of the field
    * * @param String[] - field choices
    * * @param int - initial choice index
    * * @param long - field style(see ObjectChoiceField styles)
    * */
    public CustomChoiceField(String label, String[] choices,  int initialIndex, long style)
    {
        super(label, choices, initialIndex, style);
        m_Choices = choices;
        //dimensions of selectable field
        Font currFont = getFont();
        m_DropDownArrowWidth = m_Height = currFont.getHeight();
        m_ChoiceFieldWidth = currFont.getAdvance(choices[0]);
        for(int i = 1; i < choices.length; i++)
        {
            if(m_ChoiceFieldWidth < currFont.getAdvance(choices[i]))
                m_ChoiceFieldWidth = currFont.getAdvance(choices[i]);
        }
        m_ChoiceFieldWidth += m_TextMarginLeft + m_TextMarginRight + m_DropDownArrowWidth;
    }        

    /**
    * Set field choices
    * *
    * * @param String[] - array of field choices
    * */
    public void setChoices(Object[] choices)
    {
        super.setChoices(choices);
        m_Choices = (String[])choices;
    }        

    /**
    * Set field margins. This method takes an effect for
    * * parameter to be >= 0.
    * *
    * * @param int - left margin of the field
    * * @param int - right margin of the field
    * * @param int - top margin of the field
    * * @param int - bottom margin of the field
    * */    

    public void setMargins(int marginLeft, int marginRight, int marginTop, int marginBottom)
    {
        if(marginLeft >= 0)
            this.m_MarginLeft   = marginLeft;
        if(marginRight >= 0)
            this.m_MarginRight  = marginRight;
        if(marginTop >= 0)
            this.m_MarginTop    = marginTop;
        if(marginBottom >= 0)
            this.m_MarginBottom = marginBottom;
    }        

    /**
    * Set horizontal text alignment in the text box.
    * *
    * * @param int - alignment of the text
    * */
    public void setTextHAlignment(int alignment)
    {
        m_HTextAlignment = alignment;
    }        

    /**
    * Set choice box width.
    * *
    * * @param int - choice box width.
    * */
    public void setChoiceWidth(int width)
    {
        m_ChoiceFieldWidth = width;
    }        

    /**
    * Set text font.
    * *
    * * @param int - font style (see Font class)
    * * @param int - font height
    * * @param boolean - if true control height updates according to the new font height.
    * */
    public void setTextFont(int style, int height, boolean updateHeight)
    {
        this.setFont(getFont().derive(style, height));
        if(updateHeight)
            m_DropDownArrowWidth = m_Height = getFont().getHeight();
    }        

    /**
    * Method retrieves this field's preferred width.
    * *
    * * @return int - field's preferred width
    * */
    public int getPreferredWidth()
    {
        return m_MarginLeft + m_MarginRight + m_ChoiceFieldWidth + getFont().getAdvance(getLabel());
    }        

    /**
    * Method retrieves this field's preferred height.
    * *
    * * @return int - field's preferred height
    * */
    public int getPreferredHeight()
    {
        return m_MarginTop + m_PaddingTop + m_PaddingBottom + m_MarginBottom + m_Height;
    }        

    /**
    * Determines if this field accepts the focus.
    * *
    * * @return boolean - always true.
    * */
    public boolean isFocusable()
    {
        return true;
    }        

    /**
    * Retrieves this field's current focus region.
    * *
    * * @param XYRect - object to contain the focus rect for this field in local coordinates
    * */
    public void getFocusRect(XYRect rect)
    {
        rect.set(m_MarginLeft + getFont().getAdvance(getLabel()), m_MarginTop , m_ChoiceFieldWidth, m_Height + m_PaddingBottom + m_PaddingTop);
    }        

    /**
    * Draws the focus indicator for this field
    * *
    * * @param Graphics - graphics context for drawing the focus
    * * @param boolean - true if the focus should be set; otherwise, false.
    * */
    protected void drawFocus(Graphics graphics, boolean on)
    {
        invalidate();
    }        

    /**
    * Lays out field contents.
    * *
    * * @param int - amount of available horizontal space.
    * * @param int - amount of available vertical space.
    * */
    protected void layout(int width, int height)
    {
        setExtent(Math.min(getPreferredWidth(), width), Math.min(getPreferredHeight(), height));
    }        

    /**
    * Invoked when a field receives the focus.
    * *
    * * @param int - Indicates from which direction the focus enters the field.
    * */
    public void onFocus(int direction)
    {
        m_isFocused = true;
        invalidate();
    }        

    /**
    * Invoked when a field loses the focus.
    * */
    public void onUnfocus()
    {
        m_isFocused = false;
        invalidate();
    }        

    /**
    * Method draws a edit field.
    * *
    * * @param Graphics - graphic context.
    * */
    public void paint(Graphics g)
    {
        Bitmap image = Bitmap.getBitmapResource("dropdown.png");

        String visibleText = (getSelectedIndex() == -1 || getSelectedIndex() >= m_Choices.length)?"":m_Choices[getSelectedIndex()];
        int textLength = getFont().getAdvance(visibleText);
        int labelLength = getFont().getAdvance(getLabel());
        int textY = m_MarginTop + m_PaddingTop + (m_Height - getFont().getHeight())/2;
        if(textY < 0)
            textY = m_MarginTop;                

        //Text can be as big as text box field
        while(textLength > m_ChoiceFieldWidth - m_TextMarginLeft - m_TextMarginRight - m_DropDownArrowWidth && visibleText.length() > 0)
        {
            visibleText = visibleText.substring(0, visibleText.length()-1);
            textLength = getFont().getAdvance(visibleText);
        }
        int textX = (m_HTextAlignment == TEXT_HALINGMENT_CENTER)?              m_MarginLeft + labelLength + m_TextMarginLeft + (m_ChoiceFieldWidth - m_TextMarginLeft - m_TextMarginRight - m_DropDownArrowWidth - textLength)/2:
        m_MarginLeft + labelLength + m_TextMarginLeft;
        if(textX < 0)            textX = m_MarginLeft + labelLength + m_TextMarginLeft;                

        g.setColor(0);
        g.drawText(getLabel(), m_MarginLeft, textY);
        if(m_isFocused == false)
        {
            image = Utils.resizeBitmap(image, m_ChoiceFieldWidth, m_Height + m_PaddingBottom + m_PaddingTop);
            /*
            //Draw edit box bg
            g.setColor(m_DefBgColor);
            g.fillRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height);            

            //Draw edit box rect
            g.setColor(0);
            g.drawRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height);
            //Draw edit box text
            */
            g.drawBitmap(m_MarginLeft + labelLength, m_MarginTop,  m_ChoiceFieldWidth, m_Height + m_PaddingBottom + m_PaddingTop, image, 0, 0);

            g.setColor(m_DefTextColor);
            g.drawText(visibleText, textX, textY);            

            //g.drawText(Integer.toString(cursorPosition), m_MarginLeft + labelLength + m_TextMarginLeft, textY);
        }
        else
        {
            //Draw edit box bg
            //g.setColor(m_FocusedBgColor);
            /*m_FocusedBgColor = ApplicationTheme.DEFAULT_TEXT_BOX_BACKGROUND_COLOR_ON_FOCUS;
            g.setColor(m_FocusedBgColor);
            g.fillRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height);            

            //Draw edit box rect
            g.setColor(0);
            g.drawRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height);          

            //Draw edit box bg
            g.setColor(m_DefBgColor);
            g.fillRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height);
            */

            image = Utils.resizeBitmap(image, m_ChoiceFieldWidth, m_Height  + m_PaddingBottom + m_PaddingTop);
            g.drawBitmap(m_MarginLeft + labelLength, m_MarginTop,  m_ChoiceFieldWidth, m_Height + m_PaddingBottom + m_PaddingTop, image, 0, 0);  

            //Draw edit box rect
            g.setColor(0);
            g.drawRect(m_MarginLeft + labelLength, m_MarginTop, m_ChoiceFieldWidth, m_Height + m_PaddingBottom + m_PaddingTop);
            //Draw edit box text 

            //Draw edit box text
            g.setColor(m_FocusedTextColor);
            g.drawText(visibleText, textX, textY);
        }
    }
   }

Let me know if you still have problems.

Concerning

Bika

Tags: BlackBerry Developers

Similar Questions

  • ObjectChoiceField: how to set the width of the drop-down window

    Hi guys,.

    How would you define the width of the window from the drop-down list (which displays all the elements of choice of the field of your choice)? The application automatically sets the width based on the width of the items of choice.

    Thank you

    Nitin

    Ever need to use it, so have not tried, but I note that the ObjectChoiceField includes a method called:

    getWidthOfChoice();

    Now, I assume that the width is in pixels, and that the normal process would invoke using the field.font and make a getAdvance().  But I have often wondered if, by changing it, I would change the actual width of the field.

    Maybe worth a try.  If you try it, let us know.

  • How to set the width of the comments Page?

    Every time I open the Pages, Page thumbnails and resizing automatic notes pane. I then drag the sides of the windows to resize them to a much smaller vision. A lot of time. How do we set the width of the pane for the two, so that it will not automatically resize when you open a document? Thank you.

    Pages v5.6.2 opens with miniature signs Gallery and comments to their maximum width. You can put these to scale down, save the document and exit Pages. Reopening of the same document, your previous settings are lost and these elements are maximized again. There is no magical controls that make these permanent adjustments with the same document, in all documents, or by registering as a model.

  • How to set the width in EditField

    I have my customEditField, and I put my 40 width and height using (Font.getHeight), to calculate the height. I set the max characters no. 3 when I enter 3 characters in the EditField, I see 3 characters I typed in editfield in simulaors as Pearl curve, but I couldn't see all the 3 characters in 8900, I see 2 characters only, so how do I set the width of my editField

    How can I do this?

    (i) if I have the same width, how can incase I do horizontal scrolling in my edit field

    (II) without using the scroll option, how can I determine my editfield based on my characters length maximum width (i currently use only 3 characters to type here and I need its respective width).

    Concerning

    Rakesh Shankar.p

    Agree with Stephen, here is a code which may help

    int this.getFont ().getAdvance("000") = width;

  • How to set the width of a Select list in APEX 5.0?

    Hello

    I have been using APEX 4.2 for a couple of years now. I am currently building my first application in APEX (Oracle DB 11g XE) 5.0

    On a page with multiple selection lists, I'm trying to set the width of each of them, so they are all the same size regardless of content.

    APEX 4.2, I used to just add: style = "width: 200px ' to 'ownership of the attributes of element HTML Form.

    How do I in the APEX 5.0? Property of the 'HTML Form Element attributes does not seem to exist anymore. Is there another way?

    Nick

    Hello

    You can use custom attributes: CSS min-width and max-width properties

    Concerning

    J

  • How to set the width of layout desktop screen in fluidlayout?

    For the flow layout of RWD, Web site design page I have is 960px wide. While working on DW CC, the width of sizes of support are:

    Mobile: width: 86,45%;

    Shelf width: 90.675%;

    Desktop width: 960px;

    When I set a percentage for desktop (for 960px), 68.6% (which is less mobile and the width of the Tablet), the browser displays more width 960px. Use a screen resolution of 1680X1050px.

    Now how to set the size of layout as 960px for desktop, in percentage?


    Or should I keep it as 960px for office and percentage for mobile and Tablet?

    68.6% of 1680px equals 1152px, then Yes, he is bigger than 960px

    If you want to stop at the 960px available, then set max-width: 960px to the container as well as width: 68.6%.

  • How to set the width of the column read/write rules?

    Hello specialists of the structure.

    I read a set of DITA files in a specific format to the FM model, and there is a detail that I can't work properly. It should be possible to set the width of the columns in a table, even if the DITA file does not include this information. But the developer Application Structure reference does not give information about what string to pass to the property of fm of column widths. Anyone out there experience in doing this?

    Thank you

    Jang

    I have it!

    Turned out to be simple, but the info was more or less hidden in the Dev Guide of Ref: I already had the line "property column widths fm is the value" but did not know the syntax for values. Turns out you need to delimit the values with spaces, not commas. The parser does not give ANY useful information, simply mentions "somewhere near syntax error" or completely ignores the values that you specify.

    This is how the rule for my properties DITA element works now:

    {'Properties' element

    is fm of table element;

    columns FM property value is "3".

    column and the width of the FM property value is "5cm 5cm 6 cm;

    }

    This works. I earn 10 points to answer my own question. :-)

    Ciao

    Jang

  • How to set the width of the left column?

    Hello

    I use model universal and APEX 5.0.3. I use the "left column model" of a page.

    I would like to increase the width of the left column. I have to unsubscribe from the master Thme? It does not seem desirable because "'to unsubscribe a theme will prevent future updates to the theme applied"; "

    So how to change the width of the left column?

    Thank you.

    Hello

    * arrg * navigation bar does not work with the current version of the plugin.

    In this case, take a look at the plugin and find the definition of the left box. You can find parts to copy into your page.

    Best regards

    Tobias

  • Flex 4: how 2 set Application width/height with Script?

    I'm new to Flex 4 and going through the pain of migration of 3 to 4.

    I need to set the size of my application programmatically. In Flex 3, I made this way:

    mx.core.Application.application.width = theWidth; (equivalent to the height).

    I don't know how to do this with Flex 4. Searched high and low.

    Help, please! TIA

    Bruce

    You can use the this.width, this.height and properties.

  • How to set the width of a select list?

    Hello

    an another newbie question me :-)

    When I create a list of selection the default width is 30, no matter what I set this value to the width of the selection list remains the same, it is as wide as the widest item in the list. This mess the page design. I f I have three select lists in a column, I want to have the same width. How to accomplish this?

    / Magnus

    Change the element and in the form HTML to the elements attributes field type the following:

    style="width:120px";
    

    adjust the 120 to what width you like

    Shunt

  • How to set the width of the container in sensitive (ask the dialogue) the installation program?

    I want my site to 1000px width. Just for the start of the sensitive dialogue requires dreamweaver colums how much I prefer and I can also put 3 sizes as small. Tablet and computer.

    the size of the container is always 1170. Is this a bug? Ill be grateful for the response. Zet

    In the new Document dialog box, insert the value for the big screen as in

    When the page has been created, you will see that the width is 1000px

  • How to set the width of page?

    I chose two elastic collar but the page is cramped.  Black bars

    Ben

    Based on your comments, I reviewed the css (which I don't understand) and found div width set at 46em.  I changed it to auto and the problem is solved!

    Thank you!!!

  • How to set the width of a container of spry tab without affecting other Web site?

    I have a spry with 3 legs tab container and I want to add more width to the container as a whole, but when I change the width in the Panel CSS styles, it affects all the containers on my site. How can I make a change that affects only a container, I train? Thank you!

    In code view, add a style inline, and adjust the width according to your needs:

    style = "" width: 900px ">"

    Nancy O.
    ALT-Web Design & Publishing
    Web | Graphics | Print | Media specialists
    http://ALT-Web.com/
    http://Twitter.com/ALTWEB

  • How to set the width of the column based on the width of header?

    I have a column that will contain only 1 character. It's good, but I want that column width to match the column header.

    For example,.

    Currently, I get:

    Select * from table;

    I NAME
    - ---------
    1 ROBERT

    The problem is, I want the column heading set out (in this case, it's just the ID)

    ID NAME
    -- ---------
    1 ROBERT

    Better yet,.

    If I did:

    Select the ID "Identification NUMBER", "FIRST NAME" of table name;

    I want to see:

    ID NUMBER NAME
    --------------- -----------------
    1 ROBERT

    (The ID in the column width of centering would be good too, but it's "sauce")

    Any thoughts? I tried:

    FORMAT ID COLUMN A10 (which obviously didn't work!)

    Thank you

    KSL.

    Published by: leonhardtk on August 23, 2010 11:55

    Hello

    You can check [SQL Reference | http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/functions093.htm#SQLRF00663] for syntax.

    SELECT LPAD('A', 10) FROM DUAL;
    
  • How to set the width and height of the Textarea in tabular of.

    Hello

    How the width and height of the Textarea value formatted table.



    Thank you

    Maury

    Go to the article on the report.
    go to the section of the tabular form element and the "width of the element" allows you to change the width and the 'number of lines' to change the height.

    Gus...

Maybe you are looking for

  • How to disable the TouchPad 'tap to click' on Satellite A200 - 15L Vista

    Until mid-December, I got the Synaptics Touchpad ' tap to click on "disabled. Then it became somehow activated, the context menu item to change to gray and the properties of the mouse, etc. settings contain no reference to it. It was suggested that u

  • Trying to get back to Quicktime 10 QT Pro 7

    Since the upgrade to Mac os 10.11, I had this 10 useless Quicktime on my computer, so I downloaded and installed 7 QT, but what I have is Quicktime 10.

  • How can I return to the front view before original?

    I keep having a problem that makes me nuts! I frequently design a UI façade with a lot of objects in a very limited vision (for HMI or minis screens). When starting Labview and I add a new VI, I start sizing the Panel properly and shoving everything

  • Error code: 646 (cannot install KB2092914)

    Hello I need help with this error code 646 (KB2092914), it won't let me update for microsoft 9 security update? What can I do with this issue?

  • 80072efd error code

    try to install an update, this error occurs also, my product key accepts 24 characters and said that my last character is a mistake, take courses online and home work is due tomorrow.