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. 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
If you're using swing, which it doesn't look like you are, (so why am I answering?) then all JComponents implicitly support tool tips with methods such as;
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();
}
}
精彩评论