简体   繁体   English

鼠标移动时消息上方的工具提示

[英]Tool tip over a message when mouse is moved

I am trying to show a pop up box when I move the mouse over an image. 当我将鼠标移到图像上时,我试图显示一个弹出框。 Can you please help? 你能帮忙吗?

public shopWidget extends Composite implements ClickListener {
   Image phoneImage = new Image();
   Image serviceImage = new Image();
   FlexTable flTable = new FlexTable();
   flTable.setWidget(0, 0, this.rewardsLabel);
   flTable.setWidget(1, 0, this.serviceImage);
   this.initWidget(flTable);
}

setTitle(String) displays popup text over any UIObject , including Image s. setTitle(String)在任何UIObject显示弹出文本,包括Image This is native to the browser, and only text is allowed. 这是浏览器的本机,只允许输入文本。

    Image phoneImage = new Image();
    phoneImage.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            PopupPanel p = new PopupPanel(true);
            Widget source = (Widget) event.getSource();
            int x = source.getAbsoluteLeft() + 10;
            int y = source.getAbsoluteTop() + 10;

            p.add(new Label("hi from tooltip")); // you can add any widget here
            p.setPopupPosition(x, y);
            p.show();

        }
    });

here is simple popup in gwt 这是gwt中的简单弹出窗口

如果您使用的是swing,看起来好像不是,(那么为什么我要回答?),那么所有JComponents都隐含地支持工具提示,其中包含诸如以下方法;

setToolTipText(String text)
final PopupPanel pop = new PopupPanel(false, false);
pop.setWidget(new Label("popup"));
Image image = new CustomTooltipImage(pop);
image.setUrl("http://sstatic.net/stackoverflow/img/venn-diagram.png");

Here is the custom tooltip image class: 这是自定义工具提示图像类:

public class CustomTooltipImage extends Image implements MouseOverHandler, MouseMoveHandler, MouseOutHandler
{
    private final PopupPanel tooltip;

    public CustomTooltipImage(PopupPanel tooltip)
    {
        super();
        this.tooltip = tooltip;
        addMouseOverHandler(this);
        addMouseOutHandler(this);
        addMouseMoveHandler(this);
    }

    @Override
    public void onMouseOut(MouseOutEvent event)
    {
        tooltip.hide();
    }

    @Override
    public void onMouseMove(MouseMoveEvent event)
    {
        tooltip.setPopupPosition(event.getClientX(), event.getClientY());
    }

    @Override
    public void onMouseOver(MouseOverEvent event)
    {
        tooltip.setPopupPosition(event.getClientX(), event.getClientY());
        tooltip.show();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM