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
Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified
Accepted Solution

adjustable height editfield/textbox (Please help me accomplish what rim have)

when you type a message in the bottom field (setstatus()??) on a text message from os 5 the rounded field they have adjusts its height to accomodate your text. How on earth is this accomplised? I can't find anything near to it in code samples which is where i usually start from being a novice. Can anyone offer a way to do it or even provide a code sample please?

 

regards

 

a very desperate person!

Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

dont know  if i have made myself clear in my last message, what i need is the rounded rectangle to just be white with no border but then the containing manager to be black and then all this being added as the status (setStatus()).

 

The filled rounded rectangle would be the editfield and its height would expand when the text goes on to another line. This is the bit i am stuck on.

 

Any help is appreciated.

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

Thanks for your post RexDoug, I have read through the thread but it just went over my head - i thought i was getting clever at bb coding but obviosly not.

 

Just so you know im not being lazy i will go through my thoughts on this - it might even help me!

 

The editfield wraps on its own - i had it working but in a scrollable way with a rounded rectangle being drawn in the paint method. Didnt look as good as the rim textbox for sms where it expands (height wise)

 

so im thinkink for what i want i need fillroundrect(x, x, x, x, x, x) in the paint method off the overriding editfield class. Then to control the height of the editfield i think i need to give a changing variable to setExtent(x, here).

 

If anyone can see if im on the right/wrong track please let me know - this is very much needed for myself and i suspect others in the future and i will post my full code once complete to help others,

 

Regards

 

Alex

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

What OS leveles are you targeting?  With anything OS 4.6 or later, you could always use a Border.

Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

Hi Peter,

 

 

 

I am targeting 4.7 + but please correct me if im wrong but i am thinking to just fill a rounded rectangle as there doesnt seem to be a border on the textbox with rims new sms ui (os 5+).

 

I have come up with this

 

public  class CustomEditField extends EditField
{
    
    protected void paint(Graphics g)
    {
        g.setColor(0x000000);
        super.paint(g);
    
         g.setColor(0xffffff);
        g.fillRoundRect(0, 5, Display.getWidth() - 10, 50, 10, 10);
        
        
        
    }
    
    public int getPreferredWidth()
{
       return Display.getWidth() - 10;
}
                            
protected void layout(int width,int height)
{
 super.layout(getPreferredWidth(), height);
     super.setExtent(getPreferredWidth(), getHeight());
}
   
    
    
}

 

and..

 

    HorizontalFieldManager hfm = new HorizontalFieldManager(HorizontalFieldManager.VERTICAL_SCROLL)
    {
            protected void paint(Graphics graphics) {
                           //blue
                           graphics.setBackgroundColor(0x000000);
                           graphics.clear();
                           super.paint(graphics);
                       }
                     
                       
  
    };

   
             CustomEditField tb = new CustomEditField();
             
            hfm.add(tb);
       
            setStatus(hfm);

 

 

 

this gets me as close as i have been in that the editfield does get painted as a white rounded editfield over black background and it expands upwards as each line of text is created but the text is all over and you can only see it when you're typing. (it's not in the white rounded rectangle) I hope with what I have put down what i want is clear.

 

Regards

 

Alex

Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

please if anyone can help me achive an editfield which stretches height when a newline occurs I would be in your debt forever Smiley Happy

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

Some clues:

 

Here is how I would set the preferred height of the field, based on the number of text rows and the font (assuming m_rows is the current number of rows):

 

   public int getPreferredHeight()
    {
        int fontHeight = getFont().getHeight();
        return (fontHeight * m_rows);
    }

 

You'll also have to "fix" the width, either as a property set in the constructor, or just calculate a percentage of the screen width.

 

Then, your layout() override has to look something like this:

 

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

 

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

I think the following should be relatively easy to implement:

 

1) Decide how much padding you need around the text in order for your rounded rectangle to be clearly separated. Use setPadding(int top, int right, int bottom, int left) (or setPadding(XYEdges padding))  on your text field to do that;

 

2) In order to limit the width of your TextField (BasicEditField, etc.) override its layout to do something like that:

 

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

 3) Override your text field's paint method like this:

 

protected void paint(Graphics g) {
  g.clear();
  int color = g.getColor();
  g.setColor(myRectColor);
  g.fillRoundRect(0, 0, getWidth(), getHeight(), diameter, diameter);
  g.setColor(color);
  super.paint(g);
}

Experiment with your color, padding and arc diameter values to get the view you are most pleased with.

 

 

This way, you delegate all the heavy lifting of word-wrapping to the framework, using the results of its hard work (getWidth(), getHeight()) in your fine tuning. setPadding method was not documented in earlier API versions, but it has been working the same way since API 4.0.0 and was finally documented in the most recent 6.0 version, so you can safely use it.

 

Moral of the story - if the framework can do something for you, let it do that. On the other hand, BB GUI takes a lot of time to get used to, so don't blame yourself if you miss something that seems "obvious" in hindsight.

 

Good luck!

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 93
Registered: ‎10-22-2009
My Device: Not Specified

Re: adjustable height editfield/textbox (Please help me accomplish what rim have)

Hi guys, thanks for your messages. I plan to solve this in a couple of hours when get home. Arkaydyz, does just sending height to super.layout(Math.min(width, myMaxWidth), height); will height contain the measurements which will change each time a new line is created or do i have to do what the other post said and work out font size to get the height i need for my field and then pass this worked height?

 

Thanks again, i have posted before trying as i am getting different approaches, work out the height of the field via font size * rows or does height just contain the desirable height.

 

Hope i make sense

 

Alex