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
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB
Accepted Solution

Ho to add a scroll bar on RichTextField

textbox_8520.png

 

Hi,

I developed a application where i use this type of popupScreen.

 

Here I set the  image, widht height to the Rich text Field

 

I want to set the vertical scroll for this Following is the code for this:- 

txtNote_value = new RichTextField()
{
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(graphics.getFont().derive(Font.PLAIN, 12));
super.paint(graphics);
invalidate();
}

protected void layout(int width, int height){
super.layout(width, height);
setExtent(255, 55);
}

public int getPreferredWidth(){
return width;
}

public int getPreferredHeight(){
return height;
}
};

txtNote_value.setBackground(imgTextBg);
txtNote_value.setEditable(true);
txtNote_value.setMinimalWidth(imgText_bg.getWidth());
txtNote_value.setMargin(5,2, 0, 2);

 

Can any one give me solution for scrolling the text.

 

I add this richtext field on separate vertical field manage and set the :- VerticalFieldManager.VERTICAL_SCROLL

 

but it  can scroll the hole Text filed I don't want to do this I only want to scroll the inner text of Rich text Fiedl

 

Thanks In Advance

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

Re: Ho to add a scroll bar on RichTextField

In brief, if you want to limit the size of a Field, you override its layout (or in the case of a Manager, its sublayout), and restrict the size it uses.  If you do this with the Vertical size of a scrollable VerticalFieldManager, then the contents of the VFM will scroll inside the space that been allocated to it.  I think this is what you want, so give this a go.

Please use plain text.
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

Re: Ho to add a scroll bar on RichTextField

I take the Richtect filled in side the vertical filed manage the code is as bellow,

 

vfm =new VerticalFieldManager(Manager.STATUS_MOVE_FOCUS_VERTICALLY)
            {
                public void paint(Graphics g)
                {
                    g.setBackgroundColor(Color.WHITESMOKE);
                    g.fillRoundRect(4, 1,getWidth(), getHeight(),12,12);
                    //      g.drawRoundRect(0, 0,getWidth(), getHeight(),12,12);
                     //     g.setBackgroundColor(Color.WHITE);
                       super.paint(g);
                 }
                public void sublayout(int width, int height)
                 {
                      super.sublayout(265, 73);
                      setExtent(265,73);
                      
                  }

            };

              editField = new RichTextField(Field.STATUS_MOVE_FOCUS_VERTICALLY )
              {
                public void paint(Graphics g)
                {
                getManager().invalidate();
                g.setColor(Color.BLACK);
                
                super.paint(g);
              }
            };
            editField .setMargin(5,2, 0, 5);
            editField.setEditable(true);
            Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
            
           
            editField.setBorder(bdr);
            vfm.add(editField);

 

Plz give me the solution. I not get scrollable......

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

Re: Ho to add a scroll bar on RichTextField

Not tested but try this:

 

1) remove all the Manager.STATUS_MOVE_FOCUS_VERTICALLY style settings you have.

2) Change the sublayout to the following:

                public void sublayout(int width, int height)
                 {
                      super.sublayout(265, height);
                      setExtent(this.getWidth(),73);
                     
                  }

 

Note that coding pixels like this is going to cause you problems when you try to move the application to a different device.  I would try to make these sorts of things relative, say for margins you could set them to be 1/20 of the device's screen width.  Just a thought. 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Ho to add a scroll bar on RichTextField

There are two gadgets in the knowledge base which provide you all the functionality you need:

TextBoxField revisited gives you an example of creating a vertically scrollable text box of  a predefined vertical size - if you replace EditField with RichTextField you will get what you want.

Implementing a standard style scrollbar has a substitution for VerticalFieldManager which shows a Windows-like scrollbar. Replace VerticalFieldManager with VerticalScrollManager in your modification of TextBoxField and you'll get something very similar to what you want.

 

Make sure to read comments in both articles - they contain ideas on further development.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

Re: Ho to add a scroll bar on RichTextField

1) remove all the Manager.STATUS_MOVE_FOCUS_VERTICALLY style settings you have.

2) Change the sublayout to the following:

                public void sublayout(int width, int height)
                 {
                      super.sublayout(265, height);
                      setExtent(this.getWidth(),73);
                     
                  }

 it is not work

I want to scroll the text which input on the richtextfield

Please use plain text.
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

Re: Ho to add a scroll bar on RichTextField

Hi,

My text is scrolling but the problem is that the white patch behind the text is also scrolling.

code:-

 

vfm =new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL)
            {
                public void paint(Graphics g)
                {
                    g.setBackgroundColor(Color.WHITESMOKE);
                    g.fillRoundRect(4, 1,getWidth(), getHeight(),0,0);
                    //      g.drawRoundRect(0, 0,getWidth(), getHeight(),12,12);
                      //    g.setBackgroundColor(Color.WHITE);
                       super.paint(g);
                 }
                public void sublayout(int width, int height)
                 {
                      super.sublayout(265,height ); //73
                      setExtent(this.getWidth(),73); //265
                      
                  }

            };

              editField = new RichTextField( )
              {
                public void paint(Graphics g)
                {
               // getManager().invalidate();
              g.setColor(Color.BLACK);
               // g.setBackgroundColor(Color.WHITE);
                super.paint(g);
              }
//                public void sublayout(int width, int height)
//                {
//                    super.layout(265,height ); //73
//                    setExtent(this.getWidth(),73);
//                     
//                 }
            };

 

the problem is given by

 g.fillRoundRect(4, 1,getWidth(), getHeight(),0,0);

line if i remove this then the white patch not drawn

 

I attached the output

 

Plz help me

 

8520-420.png

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Ho to add a scroll bar on RichTextField

Adjust your fillRoundRect parameters with the scrolling position:

g.fillRoundRect(getHorizontalScroll() + 4, getVerticalScroll() + 1, getWidth() - 8, getHeight() - 2, 0, 0);

 

By the way, I suspect you misplaced your parameters - the first two are the coordinates of the upper left corner of the rectangle, the last two are arcWidth and arcHeight. If I'm right and you inadvertently switched places, the call will look like:

g.fillRoundRect(getHorizontalScroll(), getVerticalScroll(), getWidth(), getHeight(), 4, 1);

 

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!
Please use plain text.
Contributor
maheshqtech
Posts: 43
Registered: ‎11-24-2011
My Device: Perl
My Carrier: BB

Re: Ho to add a scroll bar on RichTextField

thanks for ur solution it work........Thank you so much

Please use plain text.