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: 86
Registered: ‎09-01-2009
My Device: Not Specified

Problem with paint method....

I am drawing some text in the paint method. If drawing text is exceeded in the screen coordinates i want to place a scrollbar on the screen. How can i do this task.
Developer
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: Problem with paint method....

Hi,

 

You can try with following code:

 

 

public static String [] wrapText (String text, int len)
        {
                        // return empty array for null text 
                        if (text == null) 
                            return new String [] {}; 
                        // return text if len is zero or less 
                        if (len <= 0) 
                            return new String [] {text}; 
                        // return text if less than length 
                        if (text.length() <= len)
                            return new String [] {text};
                        char [] chars = text.toCharArray(); 
                        Vector lines = new Vector(); 
                        StringBuffer line = new StringBuffer(); 
                        StringBuffer word = new StringBuffer(); 
                            for (int i = 0; i < chars.length; i++)
                            {   
                                     word.append(chars[i]); 
                                                             
                                     if (chars[i] == ' ' )
                                    {    
                                        if ((line.length() + word.length()) > len)
                                        {     
                                            lines.addElement(line.toString());
                                            line.delete(0, line.length());  
                                        }   
                                            line.append(word);    
                                            word.delete(0, word.length());   
                                    } 
                            } 
             // handle any extra chars in current word
                            if (word.length() > 0)
                            {
                                if ((line.length() + word.length()) > len)
                                { 
                                        lines.addElement(line.toString());   
                                        line.delete(0, line.length()); 
                                } 
                                        line.append(word);
                            }
                            // handle extra line
                                if (line.length() > 0 )
                                {      
                                    lines.addElement(line.toString());
                                }
                                String [] ret = new String[lines.size()];
                                    int c = 0;      // counter 
                                for (Enumeration e = lines.elements(); e.hasMoreElements(); c++)
                                {  
                                    ret[c] = (String) e.nextElement(); 
                                }
                    return ret;
        }

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Developer
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Problem with paint method....

Hi,

 

Why do you need to override paint() and want to implement this type of logic.

 

There might be some other way to do it. Can you exlpain a little more.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish
Highlighted
Developer
Posts: 265
Registered: ‎08-27-2009
My Device: Not Specified

Re: Problem with paint method....

 

Gud Post....

Developer
Posts: 86
Registered: ‎09-01-2009
My Device: Not Specified

Re: Problem with paint method....

My Problem is I draw some components in the screen using the paint method. Say Some rectangle after that I want to give the some description of rectangle but if rectanle is very big that is almost end of the screen, After i added text using drawText but this text is out of screen I am unable to see the text how can I see that text one of the solution is adding the scrollbar, So how can I add scroll bar in paint method.
Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: Problem with paint method....

I;m with Rajat_10Sep here - I think there is almost certainly going to be an easier way to do what you are trying to do.

 

Say you want to draw a Rectangle.  If you know how big you want to make it, then that is easy, create Bitmap of that size, draw your rectangle on it and add this to a BitmapField for display.  Add the BitmapField to your Screen, and then add a RichTextField with the text.  Scrolling will now be done for you.

 

Remember adding a scroll bar indicator is easy, if you are going to this level you are going to have to do your own scrolling.....

 

In a normal GUI display, the scroll indicators are added by the Screen processing when it knows that there is data outside the Screen widths to be displayed.