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: 13
Registered: ‎03-18-2010
My Device: 9550
My Carrier: eclipse
Accepted Solution

How to display scrollbar on the listField

i use the following code to add a listField to VerticalManager, but it could not display a vertical scrollbar.

 

Thanks for any help.

michael

 

public class ContactsListField extends VerticalFieldManager
{

.......

 

public ContactsListField(int width, int height, String keyword)
    {
        super(Manager.NO_VERTICAL_SCROLL | Manager.FIELD_HCENTER);
        
        managerWidth = width;
        managerHeight = height;
        VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL |
                Manager.VERTICAL_SCROLLBAR | Manager.FIELD_HCENTER | Manager.FIELD_VCENTER);
        
        listField = new ListField(0,ListField.FOCUSABLE)
        {
            public void paint(Graphics g)
            {
                getManager().invalidate();
                super.paint(g);
            }
        };
        
        listCallback = new ListCallback();
        listField.setCallback(listCallback);
        
        contacts = getData();
        if (contacts != null)
            filterKeyword(keyword);
                    
        vfm.add(listField);        
        add(vfm);
    }

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

Re: How to display scrollbar on the listField

 


pekwood wrote:

 

.......

            public void paint(Graphics g)

            {
                getManager().invalidate();
                super.paint(g);
            }


As a huge favor to yourself, could you please remove the highlighted code?  You are creating an infinite loop of painting and invalidating, and even involve the whole Manager in this nonsense.  I wonder if this is the root of the problem...

 

If not, check your ListCallback's drawListRow method - you might obstruct your Manager's vertical "scrollbar" (if you can call those two small triangles scrollbar - I can't).

 

Finally, if you want a nicer-looking scrollbar which will never be overwritten by your ListField, take a look at this article:

Implementing a standard style scrollbar on a BlackBerry device

The VerticalScrollManager (which extends VerticalFieldManager and behaves very much like one) in the article steals a little room from the managed fields so that they can never paint over the scrollbar.

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 13
Registered: ‎03-18-2010
My Device: 9550
My Carrier: eclipse

Re: How to display scrollbar on the listField

Thanks very much for your replay.

 

i removed the highlight line that you told me, but it still not work well. and below is the ListCallBack code:

 

public class ListCallback implements ListFieldCallback {
    
    Vector elements = new Vector();

    public void drawListRow(ListField listField, Graphics graphics, int index,
            int y, int width) {
        
        if (index < getSize())
        {
            String text = elements.elementAt(index).toString();
            
            graphics.drawText(text, 5, y);
        }
    }

    public Object get(ListField listField, int index) {
        
        if (index >= 0 && index < getSize())
        {
            return elements.elementAt(index);
        }
        
        return null;
    }

    public int getPreferredWidth(ListField listField) {
        
        return listField.getPreferredWidth();
    }

    public int indexOfList(ListField listField, String prefix, int start) {
        
            return listField.indexOfList(prefix,start);
    }

    public void add(ListField listField, Object obj) {
        elements.addElement(obj);
        listField.setSize(getSize());        
    }

    public int getSize()
    {
        return (elements != null) ? elements.size() : 0;
    }
    
    public void remove(ListField listField, int index)
    {
        elements.removeElementAt(index);
        listField.setSize(getSize());
    }
    
    public void removeAll(ListField listField)
    {
        elements.removeAllElements();
        listField.setSize(0);
    }
}

 

Thanks again.

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

Re: How to display scrollbar on the listField

Hmm... nothing extraordinary.  One might want to draw focus in the ListField by setting appropriate background and foreground colors, but still - there is nothing that would prevent drawing of the scrollbar by the Manager.  Of course, Manager.FIELD_VCENTER is not used in VFM, and I suspect will FIELD_HCENTER will be useless too (I think ListField uses all width by default).  You might want to remove those two style bits.

 

One thing to check - what do you add that ContactListField to?  If it is a MainScreen or a derived class, you need to use NO_VERTICAL_SCROLL in the constructor.  This way you will ensure that it is vfm that handles the "scrollbar" painting.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 13
Registered: ‎03-18-2010
My Device: 9550
My Carrier: eclipse

Re: How to display scrollbar on the listField

Thank you very very very much. 

 

the problem resolved, it caused by the it's container FullScreen has a type "VERTICAL_SCROLL | VERTICAL_SCROLLBAR". it run well if i removed it.

 

But i want the FullScreen could scrollable, because in landscape mode the keyborad on the screen cover some of my field. maybe i must turn to draw a scrollbar own as you shared link of standard style scrollbar sample.

 

 

thanks for your suggestions again.