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
Highlighted
Contributor
Posts: 28
Registered: ‎08-07-2010
My Device: Not Specified
Accepted Solution

How to make half-width EditFields and more...

Hi,

I'm trying to fit two small EditField on the same row, but with no avail. I've tried setting with as you see bellow, but it always shows only the first field. Any suggestion is appreciated.

Here's my simple extention of editfield:

 

          private final class halfEditField extends EditField
          {
            private halfEditField(String label, String initialValue, int maxNumChars, long style)
            {
                super(label,initialValue, maxNumChars, style );
                setExtent(Display.getWidth()/2, getHeight());
            }              
          }

I was hoping by setting the extent to half the width of the screen, both will fit on the same row. Should I have tried with smaller width, say Display.getWidth()/2 - something ?

 

I don't want it to be horizontal scrollable, even though I tried that but I guess it is a function of the main screen itself is scrollable. Anyway I dont' want it to scroll.

A relevant question, is it possible to have an EditField with lable having a differnt color? I mean somehow the actual editable rectangle stand out and separate from the lable? The default is very lame and doesn't suggest to user that actually it is an edit rectangle there. Again I prefer to avoid addign Border since it will thicken the field and uses the scare real state on the screen.

 

I am using component 6 with simulator 9800, on eclipse.

 

 

Thansk for your suggestion.

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: How to make half-width EditFields and more...

You can't do this in the constructor. You need to override getPreferredWidth() and probably layout(int,int). Something like this should work:

 

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

protected void layout(int width, int height) {
width = Math.min(getPreferredWidth(), width);
super.layout(width, height);
}



Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 25
Registered: ‎06-08-2010
My Device: 9550
My Carrier: Verizon

Re: How to make half-width EditFields and more...

Have you looked at the HorizpntalFieldManager?

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: How to make half-width EditFields and more...

I assumed that OP was putting the fields in a HorizontalFieldManager. The problem with that by itself is that unless you do something like I showed, an EditField uses full width.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Contributor
Posts: 28
Registered: ‎08-07-2010
My Device: Not Specified

Re: How to make half-width EditFields and more...

Yes, I do add my HalfEditField to a HorizonfalFieldManager. I should have mention that in the question.

Contributor
Posts: 28
Registered: ‎08-07-2010
My Device: Not Specified

Re: How to make half-width EditFields and more...

Thanks. I'll try this and let you know.

Contributor
Posts: 28
Registered: ‎08-07-2010
My Device: Not Specified

Re: How to make half-width EditFields and more...

Kudo to you TedSmiley Happy