0

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 !!!

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
Hitarth
  • 1,950
  • 3
  • 27
  • 52

2 Answers2

3

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.

Tamar
  • 2,016
  • 1
  • 15
  • 26
  • thanx alot for suggetion. i tried to override method but it is not working . can u plz tell me how to implement this ? – Hitarth Dec 29 '11 at 04:40
2

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.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207