Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Resize autocomplete field

I want to reduce the height of my autocomplete field.How to go about it

heres my code

 

HorizontalFieldManager hfm = new HorizontalFieldManager();
   LabelField lbl = new LabelField(" Name:                 ");

       final AutoCompleteField TextField1 = new AutoCompleteField(filterLst)
        {

        public int getPreferredWidth() 
        {
            return Display.getWidth()/2;
        }

        public void sublayout(int maxWidth, int maxheight)
        {
            super.sublayout(getPreferredWidth(), getPreferredHeight());
            setExtent(getPreferredWidth(), getPreferredHeight());
        }
        };
        hfm.add(lbl);
        hfm.add(TextField1);
        add(hfm); 

  I want it to look the same size as my editfields that have been used for other labels. 

Heres the code for editfield used for other fields:

 

  

//Add box next to field for containing input 
   HorizontalFieldManager hfm1 = new HorizontalFieldManager();
   LabelField lbl1 = new LabelField(" Amount:              ");

   final EditField TextField2 = new EditField()
   {
       boolean _drawFocus = false;
        protected void layout(int maxWidth, int maxHeight) 
        {
            super.layout(Math.min(maxWidth, 300), Math.min(maxHeight, 30));
        }
       protected boolean keyChar(char ch, int status, int time) 
            {
            if (CharacterUtilities.isDigit(ch) || (ch == Characters.BACKSPACE)) 
            {
            return super.keyChar(ch, status, time);
            }
           return true;
            }
        protected void drawFocus(Graphics graphics,boolean on) 
             {
                            _drawFocus = on;
                            super.drawFocus(graphics, on);
                            _drawFocus = false;
             }    
        protected void paint(Graphics g)
            {       
                    if ( _drawFocus ) 
                    {
                            super.paint(g);
                            return;
                    } 
                     g.clear();
                    g.drawRect(0,0, 50, 50);
                    int oldColor = g.getColor();
                    g.setColor(Color.WHITE);
                    g.fillRect(0, 0, this.getPreferredWidth(), this.getPreferredHeight());
                    g.setColor(oldColor);
                    g.drawRect(100, 100, 50, 50);
                    super.paint(g);

             }

    };
   TextField2.setBorder(BorderFactory.createRoundedBorder(new XYEdges(6,6,6,6)));
   hfm1.add(lbl1);
   hfm1.add(TextField2);
   add(hfm1);

 shot6.png

I would like to have the size of autocompletefield used for name same as other fields.Please help.

Thanks

Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: Resize autocomplete field

Hi
You can use super.sublayout(getPreferredWidth(), getPreferredHeight()); to set the width/height of your autocomplete field.
Instead of getPreferredWidth, give any static value like 300 and check whether its getting change or not. It should work, because I have used like this previously.
Regular Contributor
Posts: 77
Registered: ‎05-21-2012
My Device: 9900

Re: Resize autocomplete field

Hi

Yes i have used that.Issue now is with the height.As you can see from the image above,my autocomplete field is having more height than the other fields.
When i try putting values like 40 or 20 in place of getPreferred height, it doesnt give any change.
Width is fine.Please suggest.

Thanks.
Developer
Posts: 78
Registered: ‎05-17-2012
My Device: 9900 - OS 7.0 Torch device
My Carrier: Reliance

Re: Resize autocomplete field

Try to change the extent also along with sublayout values. Extent determines, how much you are going to use. Even with Autocompletefield, you can use the settext, setfont where you can set the font with your required height.