my code stock.com

axcoro

VerticlaField Manager Scrolleable
by axcoro

Snippet options

Download: Download snippet as verticlafield-manager-scrolleable.java.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

package main.pantallas;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class VerticalScrollingFieldManager extends VerticalFieldManager
{

    private final VerticalFieldManager containerVerticalScroll;
    private int margenDerecho;
    private static final long ESTILO = Field.USE_ALL_WIDTH | Manager.NO_HORIZONTAL_SCROLL | Manager.NO_HORIZONTAL_SCROLLBAR | Field.USE_ALL_HEIGHT | Manager.FIELD_HCENTER;

    private int separacionVertical = 0;

    final int _conth = Display.getHeight();
    final int _contw = Display.getWidth();
    final int _contwin = _contw;
    final int _conthin = _conth;

    public VerticalScrollingFieldManager()
    {
	super(ESTILO);

	containerVerticalScroll = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.NO_VERTICAL_SCROLLBAR)
	{
	    public final int getPreferredWidth()
	    {
		return _contwin;
	    }

	    public final int getPreferredHeight()
	    {
		final int fields = getFieldCount();
		Field field;
		int h = 0;

		for (int i = 0; i < fields; i++)
		{
		    field = getField(i);
		    h += field.getPreferredHeight();
		}

		return h;
	    }

	    protected final void sublayout(int width, int height)
	    {
		final int fields = getFieldCount();
		Field field;
		int x = getMargenDerecho();
		int y = 0;

		for (int i = 0; i < fields; i++)
		{
		    field = getField(i);
		    setPositionChild(field, x, y);
		    layoutChild(field, width, height);
		    y += field.getPreferredHeight();
		}

		setExtent(width, height);
	    }
	};
	super.add(containerVerticalScroll);
    };

    public final int getPreferredWidth()
    {
	return this.containerVerticalScroll.getPreferredWidth();
    }

    public final int getPreferredHeight()

    {
	return this.containerVerticalScroll.getPreferredHeight();
    }

    protected final void sublayout(int width, int height)
    {
	final int fields = getFieldCount();

	if (fields == 1)
	{
	    Field field = getField(0);
	    setPositionChild(field, 2, 2);
	    layoutChild(field, _contwin, getPreferredHeight());
	}

	setExtent(_contw, getPreferredHeight());
    }

    public int getWidthManager()
    {
	return this.getPreferredWidth();
    }

    public int getHeigthManager()
    {
	return this.getPreferredHeight();
    }

    public void add(Field field)
    {
	containerVerticalScroll.add(field);
    }

    public void delete(Field field)
    {
	containerVerticalScroll.delete(field);
    }

    public int getMargenDerecho()
    {
	return margenDerecho;
    }

    public void setMargenDerecho(int margenDerecho)
    {
	this.margenDerecho = margenDerecho;
    }

    public Field getFieldWithFocus()
    {
	return containerVerticalScroll.getFieldWithFocus();
    }

    public int getSeparacionVertical()
    {
	return separacionVertical;
    }

    public void setSeparacionVertical(int separacionVertical)
    {
	this.separacionVertical = separacionVertical;
    }
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.