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
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: Height of EditField

can u show me ur code?

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

searchField = new BasicEditField("", "", 22, EditField.NO_NEWLINE|EditField.FIELD_VCENTER)
{

protected void layout(int maxWidth, int maxHeight) {
super.layout(255,30);
super.setExtent(255,30);

}
public void paint(Graphics g)
{
//super.paint(g);
//g.clear();

int fieldHeight = getFont().getHeight()+5;
int fontHeight = getFont().getHeight();
g.drawText(this.getText() ,5 , (((fieldHeight)-(fontHeight))/2));
// g.drawText(this.getText() ,5 ,10);
int oldColor = g.getColor();

g.clear();
super.paint(g);
g.setColor(Color.BLACK);
// g.fillRect(0, 0, getWidth()-10, getHeight()+15);
g.setColor(Color.GRAY);
g.drawRect(0, 0, getWidth(), getHeight());
g.setColor(Color.BLACK);
}



};
Please use plain text.
Trusted Contributor
hardikhamar
Posts: 159
Registered: ‎02-17-2011
My Device: Not Specified

Re: Height of EditField

i run ur code in simulator  9000  which works fine.

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

yes its runs fine but not showing cursor to show that Edit field has focus nd ready to input text

Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Height of EditField

In my opinion, responses on this Thread show some misunderstandings about specifying the size of a Field and especially the way layout is used.  I recommend that you all review this KB article for more information on this process.

 

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

 

Remember when you call super.layout, you are actually asking the Field to lay itself out - but you can restrict the dimensions that it uses, but that is really all you can do.  Once you have called super.layout, you need to respect the extents that it has decided upon. 

 

So for example, I believe that this is incorrect:

  public void layout (int width, int height)
   {
       super.layout (width, height);
         if (getExtent().height < getPreferredHeight())
             super.setExtent (width, getPreferredHeight());
   }

 

What you should do is this:

  public void layout (int width, int height)
   {
       super.layout (width, getPreferredHeight());
   }

 

And I think this is also wrong:

     protected void layout(int width, int height)
    {
        width = this.width;
        height = this.height;
        super.layout(width, height);
        super.setExtent(width, height);
    }

In this case, you should accept the extents the Field has decided for you within the constraints you have given it.  If you are not going to, then what is the value in calling super.layout?   

 

If you are painting the Field yourself, then you can ignore super.layout and lay the Field out yourself (which is what the KB article does) but if you are not doing the painting, then you should let the Field decide how to lay itself out so that it can then paint itself correctly. 

 

If you are painting for the Field, then it is your responsibility to all the painting.  In other words you have to know when and where the cursor is, if it is selecting and so on, and draw the focus indications.  This is not a small undertaking. 

 

Perhaps the OP can restate what they would like to see, rather than focusing on one way to achieve it. 

 

It is possible for example, to restrict a Field's height on the screen by putting in a restricted height VerticalFieldManager - in which case it can scroll within that Manager if it is too big. 

 

So rather than trying to set a specific height for a Field, identify the UI you are trying to achieve and we may be able to find an easier way to do it without rewriting EditField. 

 

 

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

I just want to display searcField (using some searchBox // simply rectangle (with border) and showing cursor to display focus on field . If i overreid paint method using above way then cursor is lost. And if dont override paint method then simly cursor is visible no rectange (searchBox) pls help me
Please use plain text.
Developer
peter_strange
Posts: 19,595
Registered: ‎07-14-2008
My Device: Not Specified

Re: Height of EditField

Are you doing this for OS 4.6 and above?

 

Have you seen the UI Fields in here:

http://supportforums.blackberry.com/t5/Java-Development/Implement-advanced-buttons-fields-and-manage...

 

From memory I think there is an EditField that has a Border around the Field which looks quite good and might do what you want too. 

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

for os 6.0

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

but this link doent contain implementation of Custom EditField

Please use plain text.
Regular Contributor
shaina123
Posts: 59
Registered: ‎03-01-2011
My Device: Not Specified

Re: Height of EditField

OK i hav sorted out using VerticalFieldMangager and adding search field in it
Please use plain text.