Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何获得codenameone中按钮的浮动帮助气泡或提示?_Codenameone - Fatal编程技术网

如何获得codenameone中按钮的浮动帮助气泡或提示?

如何获得codenameone中按钮的浮动帮助气泡或提示?,codenameone,Codenameone,我正在寻找一种方法,在用户悬停在按钮上时提供提示或帮助。按钮组件没有文本组件那样的提示。这些被称为工具提示,正如Francesco解释的,它们只在桌面应用程序中才有意义。。。由于目前还没有使用它们的标准方式,但我们确实支持它们,并在我们的桌面应用程序中使用它们 例如,此代码直接从我们的GUI builder中提取,该GUI builder以代码名1编写,具有工具提示: public static void setTooltip(Component cmp, String t) { cmp

我正在寻找一种方法,在用户悬停在按钮上时提供提示或帮助。按钮组件没有文本组件那样的提示。

这些被称为工具提示,正如Francesco解释的,它们只在桌面应用程序中才有意义。。。由于目前还没有使用它们的标准方式,但我们确实支持它们,并在我们的桌面应用程序中使用它们

例如,此代码直接从我们的GUI builder中提取,该GUI builder以代码名1编写,具有工具提示:

public static void setTooltip(Component cmp, String t) {
    cmp.putClientProperty("tooltip", t);
}

public static void showTooltip(Component cmp, Form f) {
    final String t = (String)cmp.getClientProperty("tooltip");
    if(t == null) {
        f.setGlassPane(null);
    } else {
        int offset = Display.getInstance().convertToPixels(2) + 10;
        final Font fnt = cmp.getUIManager().getComponentStyle("Label").getFont();
        int width = fnt.stringWidth(t);
        int height = fnt.getHeight();

        int x = cmp.getAbsoluteX();
        if(x > f.getWidth() / 2) {
            x -= (width + offset);
        } else {
            x += cmp.getWidth() + offset;
        }
        int y = cmp.getAbsoluteY();
        if(y > f.getHeight() / 2) {
            y -= (height + offset);
        } else {
            y += cmp.getHeight() + offset;
        }

        final Rectangle rect = new Rectangle(x, y, width + 10, height + 10);
        final Rectangle shadow = new Rectangle(x + 5, y + 5, width + 10, height + 10);
        final Stroke s = new Stroke(3, Stroke.CAP_ROUND, Stroke.JOIN_ROUND, 1);
        f.setGlassPane(new Painter() {
            @Override
            public void paint(Graphics g, Rectangle r) {
                g.setColor(0);
                g.setAlpha(120);
                g.fillShape(shadow);
                g.setAlpha(255);
                g.setColor(0xeeeeee);
                g.fillShape(rect);
                g.setColor(0);
                g.drawShape(rect, s);
                g.setColor(0);
                g.setFont(fnt);
                g.drawString(t, rect.getX()  + 5, rect.getY() + 5);
            }
        });
    }
}
此代码应采用
格式
子类:

@Override
public void pointerHover(int[] x, int[] y) {
    Component c = getComponentAt(x[0], y[0]);
    if(c != null) {
        GuiBuilderUtils.showTooltip(c, this);   
    }        
}

您的请求是否仅适用于台式机?在触摸屏设备中,不按按钮是不可能悬停的。我如何在触摸屏设备上实现Codenameone中的工具提示?我将尝试一下,看看它在我的用例中是如何工作的。谢谢