简体   繁体   English

带GWT的FlexTable的MouseOver

[英]MouseOver of FlexTable with GWT

Hello everyone I have a FlexTable that contains images (one for each cell). 大家好,我有一个包含图像的FlexTable(每个单元格一个)。 I wish I had an event that you move your mouse over the cell comes out a popup that should contain the title of the image. 希望我有一个事件,将鼠标移到单元格上方,弹出一个应包含图像标题的弹出窗口。 Someone can give me a hand? 有人可以帮我吗?

I tried to insert this code does what he must do (at least for me) but the popup remains active when I remove the mouse pointer .where I wrong? 我试图插入此代码执行他必须做的事情(至少对我来说),但是当我删除鼠标指针时,弹出窗口仍然处于活动状态。我在哪里弄错了?

private FlexTable createHTML(ImageResult result,int row,final int i,int currentCol) {

 immagine[i]=new Image(result.getThumbnailUrl());
 resultsTableImm.setWidget(row, currentCol, immagine[i]);
 titleImm[i]=result.getTitleNoFormatting();
 contentImm[i]=result.getContentNoFormatting();
 urlImm[i]=result.getUnescapedUrl();

 immagine[i].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 HTML("<b>"+titleImm[i]+"</b><br>"+contentImm[i])); 
            p.setPopupPosition(x, y);
        p.show();
        }
    });

    return resultsTableImm;
            }

Thank you and have a nice day 谢谢你,祝你有美好的一天

JD 京东

FlexTable hasn't onMouseOverHandler . FlexTable还没有onMouseOverHandler It only has clickHandler . 它只有clickHandler So you can't attach mouse over handler to the table(cell). 因此,您不能将鼠标悬停在处理程序上到表(单元格)。 One way is addMouseOverHandler to the image show them in the popuplike that 一种方法是将addMouseOverHandler添加到图像中,将它们显示在弹出窗口中,如下所示:

Image image= new Image();
image.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(image); 
            p.setPopupPosition(x, y);
            p.show();
        }
    });

If you use gwt2.1 then I suggest you to use CellTable 如果您使用gwt2.1,那么我建议您使用CellTable

Look at this example Cell Table 看这个例子单元格表

Boiling down Xorty's example to the essentials of the present question you may adapt the following extension of FlexTable: 将Xorty的示例总结为当前问题的要点,您可以采用以下FlexTable扩展:

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.FlexTable;

public class PTable extends FlexTable {

    public static final String ROW_STYLE_NAME  = "pm-PTable-row";

    PTable() {
        setStyleName("pm-PTable");
        sinkEvents(Event.ONMOUSEOVER |Event.ONMOUSEOUT); 
    }

    @Override
    public void onBrowserEvent(Event event) {
        super.onBrowserEvent(event);
        Element td = getEventTargetCell(event);
        if (td == null) return;
        Element tr = DOM.getParent(td);
        switch (DOM.eventGetType(event)) {
            case Event.ONMOUSEOVER: {
                tr.addClassName(ROW_STYLE_NAME + "-mouseover");
                break;
            }
            case Event.ONMOUSEOUT: {
                tr.removeClassName(ROW_STYLE_NAME + "-mouseover");
                break;
            }
        }
    }
}

You can make custom widget with registered onmouseover handler and place it to flex table (idea is not trying to add listener for cell, but have it on widget itself which resides in cell). 您可以使用注册的onmouseover处理程序制作自定义窗口小部件,并将其放置到flex表中(想法不是试图为单元格添加侦听器,而是将其放在单元格中的窗口小部件本身上)。

Or you can try something like this: http://www.java2s.com/Code/Java/GWT/TableMouseOverEvent.htm 或者,您可以尝试执行以下操作: http : //www.java2s.com/Code/Java/GWT/TableMouseOverEvent.htm

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

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