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
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----
Accepted Solution

how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

The following snippet contains a horizontal field manager to which five buttons are added.

1. I am unable to set horizontal scroll to the horizontal field manager because of which I am not able to access button 4 and button 5.

2. Usually we set horizontal scroll in the following manner:

 

container = new HorizontalFieldManager(USE_ALL_WIDTH|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR);

 

3. So,  I  also tried setting horizontal scroll in the following manner

 

   container = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL|Manager.HORIZONTAL_SCROLLBAR)
			{
		    
				protected void sublayout(int maxWidth, int maxHeight) {
					
					Field field = null;
			    	int x = 0;
			    	int y = 0;
			    	int maxFieldHeight = 0;
			    	int maxFieldWidth = 0;
			    	for (int i = 0; i < getFieldCount(); i++) 
			    	{
			    		field = getField(i);
			    		layoutChild(field, maxWidth, maxHeight);
				    	setPositionChild(field, x/*width-field.getWidth()*/,y);
			    		
			    		x+=field.getWidth();
			    		
			    		maxFieldWidth = maxFieldWidth + field.getWidth();
			    		System.out.println("field width"+field.getWidth());
			    		System.out.println(" max field width"+maxFieldWidth);

			    		
			    		if(i==0)
			    		{
			    			maxFieldHeight = field.getHeight(); // height set of the first button since all components have the same height
			    		}
			    	}
		    		System.out.println("final max field width"+maxFieldWidth);

			    	setExtent(maxFieldWidth, maxFieldHeight);
			    	
				}
			};

but its not working.

 

4. I found this property : horizontalFieldManager.setHorizontalScroll(position); which contains the ParameterSmiley Tongueosition where position is supposed to be the new horizontal scroll position. I tried passing the x-coordinate of the horizontal field manager but it's not working. What should i pass as the position parameter?

 

HorizontalFieldManager container = new HorizontalFieldManager()
{  
    protected void sublayout(int maxWidth, int maxHeight) 
    {   
        Field field = null;
        int x = 0;
        int y = 0;
        int maxFieldHeight = 0;
        for (int i = 0; i < getFieldCount(); i++) 
        {
            field = getField(i);
            layoutChild(field, maxWidth, maxHeight);
            setPositionChild(field, x,y);
            x+=field.getWidth();
            if(i==0)
            {
                maxFieldHeight = field.getHeight(); // height set of the first button since all components have the same height
            }
        }

        setExtent(Display.getWidth(), maxFieldHeight);

    }
};

ButtonField button1 = new ButtonField("Button1");
ButtonField button2 = new ButtonField("Button2");
ButtonField button3 = new ButtonField("Button3");
ButtonField button4 = new ButtonField("Button4");
ButtonField button5 = new ButtonField("Button5");

container.add(button1);
container.add(button2);
container.add(button3);
container.add(button4);
container.add(button5);

add(container);

 Need your valuable comments and suggestions. Please help me.

Developer
Posts: 172
Registered: ‎01-02-2012
My Device: 8520 curve
My Carrier: compny

Re: how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

Add horizontal scroll style in horizontal manager as a parameter

new HorizontalFieldManager(HORIZONTAL_SCROLL)

 

and make each button filed Focusable.

 

 

or


Use vertical manager with horizontal scroll style and horizontal manager in to vertical manager

 

But make sure that all chilled field should be focusable.

 

Try it.......

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

Re: how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

I think there is a bug in the sublayout(0 method of your HorizontalFieldManager.  Since that code is doing what I think HFM will do anyway, I recommend that you try doing this with a standard HFM, using this style:

Manager.HORIZONTAL_SCROLL|Manager.HORIZONTAL_SCROLLBAR

Let us know how you get on. 

 

When I have more time I will explain the bug, but if you wanted to investigate something, be aware that the maximum dimensions that you can use in setExtent are the values that are passed in to sublayout.  Compare the width you try to set in setExtent with the width that is passed in. 

Contributor
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

@peter yes the code in the sublayout performs the same as the HFM sp I am gonna opt for the standard HFM. Thank you for your suggestion. Please could you elaborate on the bug in the sublayout method whenever you have time?

Contributor
Posts: 17
Registered: ‎06-07-2013
My Device: Blackberry Curve - 9300
My Carrier: ----

Re: how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

@avinash Thank you. I am going to use standard HFM  as peter suggested and set horizontal scroll in the constructor.

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

Re: how to set horizontal scroll to horizontal field manager when fields are added using a for loop?

I recommend this KB article to help understand:

 

http://supportforums.blackberry.com/t5/Java-Development/Implementing-a-standard-style-scrollbar-on-a...

 

The point is that each Manager is given an area that it can display its contained Fields.  This is the maximum size of the Window that it uses to paint into.  Sometimes this window is actually smaller than the area the Manager needs.  In that case it has to set its 'virtual' size, and then scroll within the window. 

 

In this case I think you were trying to set a Window size (extent) that was bigger than the space that was available to you (passed in).  So you really had to scroll and set the virtual extent.

 

BTW, if you review the article, review the comments too - as there is another class provided that does the scrolling in a better way I think.