如何在 BasicEditField 中禁用无限滚动

发布于 2024-12-23 02:25:12 字数 1644 浏览 2 评论 0原文

大家好,我已经实现了自定义 BasicEditField 来设置提示并输入长文本。

请参阅我的代码

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);
            }}

有一个 Horizo​​ntalFieldManager 来滚动文本。

hfm_searchBox = new Horizo​​ntalFieldManager(Manager.HORIZONTAL_SCROLL) ;

有一个Basiceditfield用于输入文本。

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);
                }

            }};

BasicEditFieldBackgroundimagehint 一起看起来不错,但问题是,当我在文本字段中没有输入任何内容时,它会以无限滚动的方式工作。我已设置 Horizo​​ntalfield 宽度取决于 BasiceditField 但其宽度默认设置为 unlimited 。

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

如何防止无限滚动?

提前致谢 !!!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人生百味 2024-12-30 02:25:12

Horizo​​ntalFieldManager 的 虚拟宽度?这是指可滚动空间,而宽度是指屏幕上的范围。您可以尝试扩展 Horizo​​ntalFieldManager 并覆盖 sublayout 方法,调用 setVirtualExtent 在其中。

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.

冰雪梦之恋 2024-12-30 02:25:12

正如 Tamar 所说,字段的虚拟宽度是需要跟踪的关键概念。

您可以在此处查看我对非常类似问题的解决方案。我提供了一个完整的代码示例,它可能与您想要做的事情相去不远。我使用的代码更进一步,动态地将滚动限制为仅滚动到文本当前到达的位置的末尾。如果您不这样做,而只是设置一个恒定的虚拟宽度,那么您可能会让该字段实际上向右滚动太远。通过动态调用 setVirtualExtent(),您始终会获得足够的滚动,但不会太多。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文