how to disable endless scroll in BasicEditField

439 Views Asked by At

HI all i have implement Custom BasicEditField to set hint and to input long text .

please see my code

vfm_searchBox = new VerticalFieldManager()
        {
            //Main.Quicksearchinput is background image for inputtext
            public void paint(Graphics g)
            {   
                g.setColor(Color.WHITE);
                g.drawBitmap(0,0,Main.Quicksearchinput.getWidth(),Main.Quicksearchinput.getHeight(),Main.Quicksearchinput,0,0);
                super.paint(g);
            }}

There is one HorizontalFieldManager to scroll text.

hfm_searchBox = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL) ;

There is one Basiceditfield to input text .

txtSearch = new BasicEditField(BasicEditField.NO_NEWLINE)
        {
            public void paint(Graphics g)
            {
                if(super.getText().length() == 0)
                {
                    g.setColor(Color.GRAY);
                    g.setFont(g.getFont().derive(Font.PLAIN,18));
                    g.drawText("Enter Event title or subtitle", 0, 0);
                    super.paint(g);
                }
                else
                {
                    g.setColor(Color.BLACK);
                    super.paint(g);
                }

            }};

The BasicEditField looks nice with Backgroundimage and hint but problem is that when i am nothing input in textfield it is working as endless scroll . i have set Horizontalfield width depend on BasiceditField but its width by default set to unlimited .

hfm_searchBox.add(txtSearch);
vfm_searchBox.add(hfm_searchBox);

how to prevent endless scroll ?

Thanks in Advance !!!

2

There are 2 best solutions below

1
Tamar On

What is the HorizontalFieldManager's virtual width? This refers to the scrollable space whereas the width refers to the extent on the screen. You can try extending HorizontalFieldManager and overriding the sublayout method, calling setVirtualExtent in it.

0
Nate On

As Tamar said, the Field's Virtual Width is the key concept to keep track of.

You can see my solution to a very similar question here. I provide a full code example that's probably not too far from what you're trying to do. The code I use goes a step further, and dynamically limits scrolling only to the end of where the text currently reaches. If you don't do this, and simply set one constant virtual width, then you can have the field actually scroll too far to the right. By dynamically calling setVirtualExtent(), you always get just enough scrolling, but not too much.